I tried grep -v '^$'
in Linux and that didn't work. This file came from a Windows file system.
相关问题
- React Native Inline style for multiple Text in sin
- How to change the first two uppercase characters o
- Is there a way to rotate text around (or inside) a
- Execute C program till Ctrl+C hit in the terminal
- Gulp BrowserSync showing “reloading browsers” in T
相关文章
- 放在input的text下文本一直出现一个/(即使还没输入任何值)是什么情况
- What's the difference between grep -r and -R
- Emacs/xterm color annoyance on Linux
- make GitX open via Terminal for the repo laying at
- Ruby grep with line number
- Rendering plain text through PHP
- Shell Removing Tabs/Spaces
- JSON.parse with newline [duplicate]
If you have sequences of multiple blank lines in a row, and would like only one blank line per sequence, try
cat -s
suppresses repeated empty output lines.Your output would go from
to
The three blank lines in the original output would be compressed or "squeezed" into one blank line.
Using Perl:
\S
means match non-blank characters.Same as above answers
Here, grep -e means extended version of grep. '^$' means that there is no character between ^(Start of line) and $(end of line). '^' and '$' are regex characters.
So the command grep -v will print all the lines that do not match this pattern (No characters between ^ and $).
This way empty blank lines are eliminated
here is another way of removing the white lines and lines starting with # sign. I think this is quite useful to read configuration files.
Try the following:
The
-e
option allows regex patterns for matching.The single quotes around
^$
makes it work for Cshell. Other shells will be happy with either single or double quotes.UPDATE: This works for me for a file with blank lines or "all white space" (such as windows lines with "\r\n" style line endings), whereas the above only removes files with blank lines and unix style line endings:
Or just simply awk
If you don't have dos2unix, then you can use tools like tr