The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to delete empty lines Aejaz UNIX for Advanced & Expert Users 5 04-30-2008 07:27 AM
display all lines shary Shell Programming and Scripting 3 02-17-2007 12:09 PM
delete multiple empty lines whatisthis Shell Programming and Scripting 3 11-09-2005 01:42 PM
How will you list only the empty lines in a file (using grep) JosephGerard UNIX for Dummies Questions & Answers 1 07-21-2005 12:19 AM
cat and empty lines Nicol Shell Programming and Scripting 4 11-13-2003 05:19 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-22-2006
Registered User
 

Join Date: Mar 2006
Posts: 18
display no of empty lines

I want to display the number of empty lines in a file. I guess i should use 'grep'...but how..
10x for those who'll help.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-22-2006
Registered User
 

Join Date: Jan 2005
Posts: 682
Quote:
Originally Posted by atticus
I want to display the number of empty lines in a file. I guess i should use 'grep'...but how..
10x for those who'll help.
Nah, use awk.
Reply With Quote
  #3 (permalink)  
Old 03-22-2006
Registered User
 

Join Date: Feb 2006
Posts: 10
# of empty lines
Code:
grep -n ^$ filename | wc -l
lines that are empty
Code:
grep -n ^$ filename | tr -d :
...
to remove all empty lines
Code:
grep -v ^$ filename >newfilename

Last edited by stobo; 03-22-2006 at 07:23 AM.
Reply With Quote
  #4 (permalink)  
Old 03-22-2006
Registered User
 

Join Date: Mar 2006
Location: Mumbai,India
Posts: 57
user egrep

1] you can use the egrep command like
egrep [a-z,a-Z,0-9] testfile.txt >> new.txt
[ it will extract the all rows but except the blank rows]

2] then take the line count of the bth the files using
wc -l testfile.txt -- [ say 15 with 5 blank lines] and
wc -l new.txt [ it will give you only 10 lines]
rm new.txt
now substract the both values you will get the total blank values in your file

Hope it will help you

Regards,
Swapneel
Reply With Quote
  #5 (permalink)  
Old 03-22-2006
Registered User
 

Join Date: Jan 2005
Posts: 682
nawk '/^$/ {n++} END{print n}' yourfile
Reply With Quote
  #6 (permalink)  
Old 03-22-2006
Registered User
 

Join Date: Mar 2006
Posts: 18
10q guys

Thanks for the help, this also works:

grep -ca ^$ filename

10x especially for stobo īs reply.
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:15 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0