GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Operating System  >  Shell Scripting
Go To First  |  Previous Question  |  Next Question 
 Shell Scripting  |  Question 11 of 47    Print  
How will you list only the empty lines in a file (using grep)?

  
Total Answers and Comments: 6 Last Update: June 05, 2009   
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
June 03, 2005 06:23:10   #1  
dkbaba        

RE: How will you list only the empty lines in a file (using grep)?
grep ^$ filename.txt
 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
July 09, 2005 07:35:27   #2  
giri        

RE: How will you list only the empty lines in a file (using grep)?
grep -c ^$ filename.txt

 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
February 15, 2006 06:59:22   #3  
Pallavii Potdaar        

RE: How will you list only the empty lines in a file ...

grep ^[ ]*$ filename.txt

In character set (between [ and ] one space and tab is given)

this command will gives all the blank line including those having space and tabs (if pressed)only


 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
June 04, 2008 18:58:32   #4  
Vivek12 Member Since: June 2008   Contribution: 3    

RE: How will you list only the empty lines in a file (using grep)?
We can do this efficiently through awk script

awk '{
if (NF 0)
{
print "Here comes the empty line"
print $0
}
}' filename

NF number of fields in the current line
$0 current line

 
Is this answer useful? Yes | No
March 19, 2009 20:57:58   #5  
gcvpgeek Member Since: March 2009   Contribution: 9    

RE: How will you list only the empty lines in a file (using grep)?
use the below command to fetch the blank lines

grep -v . filename

 
Is this answer useful? Yes | No
June 05, 2009 05:25:22   #6  
Rohit_Ash Member Since: May 2009   Contribution: 6    

RE: How will you list only the empty lines in a file (using grep)?
Both of these work.

cat test.sh | grep ^$

grep -v . test.sh

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape