Remove all blank lines in shell or awk. | Unix Linux Forums | Shell Programming and Scripting

  Go Back    

Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Remove all blank lines in shell or awk.

Shell Programming and Scripting

awk, awk trim, trim, trim awk

Closed Thread    
Thread Tools Search this Thread Display Modes
Old 10-13-2008
tushar_tus tushar_tus is offline
Registered User
Join Date: Aug 2008
Last Activity: 27 November 2009, 2:10 AM EST
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Remove all blank lines in shell or awk.

Hi there,

I want to trim space between lines in unix.
I have a file named abc.txt with 2,00,000 lines.But useful are only a few. Please tell me how to delete the blank lines.
Sponsored Links
Old 10-13-2008
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
Join Date: Mar 2007
Last Activity: 21 January 2015, 4:24 PM EST
Location: Toronto, Canada
Posts: 2,882
Thanks: 0
Thanked 116 Times in 105 Posts

Take your pick:

tr -s '\n' < abc.txt

grep -v "^$" abc.txt

sed '/^$/d' abc.txt

sed '/./!d' abc.txt

awk '/./' abc.txt

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to remove blank lines mayursingru Shell Programming and Scripting 13 05-26-2011 08:35 AM
Delete blank lines, if blank lines are more than one using shell anil8103 Shell Programming and Scripting 5 05-10-2011 08:21 PM
remove blank lines and merge lines in shell dvah Shell Programming and Scripting 11 03-09-2011 09:45 AM
Remove blank lines KidCactus Shell Programming and Scripting 9 10-05-2010 12:37 PM
Shell script: Remove blank lines gholdbhurg Shell Programming and Scripting 3 02-25-2009 02:33 PM

All times are GMT -4. The time now is 07:08 AM.