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


Tags
awk, awk trim, trim, trim awk

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
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
    #2  
Old 10-13-2008
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
 
Join Date: Mar 2007
Last Activity: 18 June 2014, 3:49 PM EDT
Location: Toronto, Canada
Posts: 2,875
Thanks: 0
Thanked 110 Times in 102 Posts

Take your pick:


Code:
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 07:35 AM
Delete blank lines, if blank lines are more than one using shell anil8103 Shell Programming and Scripting 5 05-10-2011 07:21 PM
remove blank lines and merge lines in shell dvah Shell Programming and Scripting 11 03-09-2011 08:45 AM
Remove blank lines KidCactus Shell Programming and Scripting 9 10-05-2010 11:37 AM
Shell script: Remove blank lines gholdbhurg Shell Programming and Scripting 3 02-25-2009 01:33 PM



All times are GMT -4. The time now is 09:55 PM.