Computing.Net > Forums > Unix > blank lines and sed

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

blank lines and sed

Reply to Message Icon

Name: alrinno
Date: July 15, 2008 at 23:15:31 Pacific
OS: UNIX
CPU/Ram: N/A
Product: Any
Comment:

----------------------

hello,

i have tried to remove blank lines from a file using korn shell script file.. it doesn't seem to work!

i tried sed '/^\s*$/d' infile > outfile but that didn't work
i tried sed 's/ *$//;/^$/d' infile > outfile and that didn't work
i tried sed '/^s./d' infile > outfile and that didn't work

what can i do? this is a huge file and some blank lines might be spaces? or tabs? how can i know?

thank you



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: July 16, 2008 at 09:59:38 Pacific
Reply:

On my Solaris 9 box, this works:

#!/bin/ksh

sed '/^[ ]*$/d' tfile

Be advised that with the above one-liner between the brackets:

[ ]

is a space bar and a tab key. Some versions of sed allow using \t as a tab.


0

Response Number 2
Name: lankrypt0
Date: July 16, 2008 at 12:42:19 Pacific
Reply:

if it does not have to be sed, you could use tr:
tr -s "\n"


0

Response Number 3
Name: nails
Date: July 16, 2008 at 13:04:19 Pacific
Reply:

The tr solution handles only newlines; it does not handle lines that are all spaces or tabs.


0

Response Number 4
Name: James Boothe
Date: July 16, 2008 at 15:19:08 Pacific
Reply:

awk can check for Number of Fields greater than zero.

awk 'NF>0' infile > outfile


0

Response Number 5
Name: alrinno
Date: July 17, 2008 at 10:40:47 Pacific
Reply:

Thank you all for your help!!!


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: blank lines and sed

Remove blank lines between two line www.computing.net/answers/unix/remove-blank-lines-between-two-line/5208.html

delete blank line thro vi editor www.computing.net/answers/unix/delete-blank-line-thro-vi-editor/4552.html

Removing blank lines www.computing.net/answers/unix/removing-blank-lines/5139.html