removing blank lines in a text file
how do I delete all blank lines in a text file? thanks :)
|
There are a thousand ways to do that. If you want to do it from the ci:
Code:
cat file-blanklines-2-be-deleted | sed -e '/^$/d' | tee newfile-no-blanklines Code:
:g/^[ t]*$/d --> WHERE t=tab |
Look at table C-2 --> http://tldp.org/LDP/abs/html/abs-guide.html#AEN20423
|
Used this in the past to strip blank lines and comments
Code:
sed '/ *#/d; /^ *$/d' test.txt2 |
Why couldn't you just use: sed /^$/d < oldfile > newfile
|
I prefer grep:
#print only lines that contain non-whitespace characters grep '[^[:space:]]' oldfile > newfile |
Quote:
Code:
sed -e '/^$/d' file-blanklines-2-be-deleted Code:
sed -ie '/^$/d' file-blanklines-2-be-deleted |
or vi the file and in command mode do this:
Code:
%s/ //g |
Quote:
|
If you want to modify the original file (instead of creating a second, modified one), you can use the -i option. This version also deletes lines with spaces and tabs on... maybe you want to keep them, I don't know:
Code:
sed -i '/^[ \t]*$/d' the_file_to_modify |
Quote:
Code:
g/^$/d |
That's the ticket. You could also use \s in that to get lines that have non-printing chars:
Code:
: %s:\s:g |
All times are GMT -5. The time now is 12:18 AM. |