Unix/Linux Go Back    

Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Remove all blank lines in shell or awk.

Shell Programming and Scripting

awk, awk trim, trim, trim awk

Thread Tools Search this Thread Display Modes
Old Unix and Linux 10-13-2008   -   Original Discussion by tushar_tus
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.Linux
Sponsored Links
Old Unix and Linux 10-13-2008   -   Original Discussion by tushar_tus
cfajohnson's Unix or Linux Image
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
Join Date: Mar 2007
Last Activity: 11 July 2016, 2:55 PM EDT
Location: Toronto, Canada
Posts: 2,898
Thanks: 0
Thanked 134 Times in 118 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

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 11:44 AM.