Hi there,
What is the command line do you use to delete all blank line in a file with sed command.
I had tried for a week but could not success. I am new in this toy. Please help.
Thanks.
This will remove blank empty lines but not if they contain white space.
[sig]<p>Ged Jones<br><a href=mailto:gedejones@hotmail.com>gedejones@hotmail.com</a><br><a href= > </a><br>Top man[/sig]
If all the lines of data contain alpha you could also try :-
sed '/[A-z]/!d' < infile > outfile
or for numeric
sed '/[0-9]/!d'
Note, [A-z] is for all upper and lower case alpha charecters. !d means delete lines not containing the string charecters. [sig]<p>Ged Jones<br><a href=mailto:gedejones@hotmail.com>gedejones@hotmail.com</a><br><a href= > </a><br>Top man[/sig]
If you have to use sed, it's not too different from the "grep" command suggested by Ged:
[tt]
sed -e's/^$//' input_file_name > new_file_name
[/tt]
This passes the file "input_file_name" into sed, which swaps all blank lines for nothing, and sends the output to "new_file_name".
[sig]<p> Andy Bold<br><a href=mailto: > </a><br><a href= > </a><br>"I've probably made most of the mistakes already, so hopefully you won't have to..." Me, most days.[/sig]
Maybe this can be helpful, from the the Unix Command Compendium,
sed '/--*$/{n;/^$/d;}' file_name
This example deletes blank lines that follow the first regular expression--which, for example purposes, consists of two or more hyphens. The n command tells sed to process the line following this regular expression. Next, the regular expression /^$/ specifies that only blank lines should be processed. Finally, the d command tells sed to delete the blank lines.
sed '{n;/^$/d;}' file_name > new_file_name
The above will remove all blank lines from your file. If you have to do this repeatedly to many files I would suggest you script this and use variables for file_name and new_file_name.>:O> [sig][/sig]
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.