Quantcast
Channel: How to remove empty/blank lines from a file in Unix (including spaces)? - Server Fault
Browsing all 10 articles
Browse latest View live

Answer by christian elsee for How to remove empty/blank lines from a file in...

xargs if you dont mind stripping leading whitespace $ docker run -it --rm alpine sh/ # cat <<eof > /tmp/file> one>> two> three>>> four> eof/ # cat /tmp/fileone twothree...

View Article



Answer by ishandutta2007 for How to remove empty/blank lines from a file in...

For me @martigin-heemels command was throwing error this fixed it (ie a dummy param to i),sed -i '''/^$/d' file.txt

View Article

Answer by Zombo for How to remove empty/blank lines from a file in Unix...

Here is an awk solution:awk NF file.txtWith Awk, NF only set on non-blank lines. When this condition match, Awk default action is to print the whole line.

View Article

Answer by kenorb for How to remove empty/blank lines from a file in Unix...

Ex/VimHere is the method using ex editor (part of Vim):ex -s +'v/\S/d' -cwq test.txtFor multiple files (edit in-place):ex -s +'bufdo!v/\S/d' -cxa *.txtNote: The :bufdo command is not POSIX.Without...

View Article

Answer by siddhadev for How to remove empty/blank lines from a file in Unix...

To remove empty lines, you could squeeze new line repeats with tr:cat file.txt | tr -s '\n''\n'

View Article


Answer by kenorb for How to remove empty/blank lines from a file in Unix...

grepSimple solution is by using grep (GNU or BSD) command as below.Remove blank lines (not including lines with spaces).grep . file.txtRemove completely blank lines (including lines with spaces).grep...

View Article

Answer by jdabney for How to remove empty/blank lines from a file in Unix...

You can use the -v option with grep to remove the matching empty lines.Like thisgrep -Ev "^$" file.txt

View Article

Answer by Martijn Heemels for How to remove empty/blank lines from a file in...

This sed line should do the trick:sed -i '/^$/d' file.txtThe -i means it will edit the file in-place.

View Article


Answer by Kamil Kisiel for How to remove empty/blank lines from a file in...

sed '/^$/d' file.txtd is the sed command to delete a line. ^$ is a regular expression matching only a blank line, a line start followed by a line end.

View Article


How to remove empty/blank lines from a file in Unix (including spaces)?

How do I remove empty/blank (including spaces only) lines in a file in Unix/Linux using the command line?contents of...

View Article
Browsing all 10 articles
Browse latest View live




Latest Images