display no of empty lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting display no of empty lines
# 1  
Old 03-22-2006
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.
# 2  
Old 03-22-2006
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.
# 3  
Old 03-22-2006
# 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 11:23 AM..
# 4  
Old 03-22-2006
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
# 5  
Old 03-22-2006
nawk '/^$/ {n++} END{print n}' yourfile
# 6  
Old 03-22-2006
10q guys

Thanks for the help, this also works:

grep -ca ^$ filename

10x especially for stobo īs reply.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Joining broken lines and removing empty lines

Hi - I have req to join broken lines and remove empty lines but should NOT be in one line. It has to be as is line by line. The challenge here is there is no end of line/start of line char. thanks in advance Source:- 2003-04-34024|04-10-2003|Claims|Claim|01-13-2003|Air Bag:Driver;... (7 Replies)
Discussion started by: Jackceasar123
7 Replies

2. Shell Programming and Scripting

Remove CR only on empty lines

Dear community, I have two output files that contains some CR # cat first.out 1234567890 598679857648566 9 1234567234 365837465873465 4 2342343243 289374982374894 4 # cat second.out 2342342342 ... (2 Replies)
Discussion started by: Lord Spectre
2 Replies

3. Shell Programming and Scripting

delete lines with empty second column

hi, I'd like to ask you if you can help me with such surely easy thing - I have some data and need to plot them. I have txt of data in two columns, tab separated, but some second columns are empty. like 1```` 2 1.2`` 3```` 2 4.44` 5````` 6.1```1 how can I erase all the lines... (2 Replies)
Discussion started by: bsco
2 Replies

4. Shell Programming and Scripting

using vi -c to remove empty lines

Hello: I searched here for "vi -c" but found no hits. How can I use vi -c to remove ALL empty lines, regardless of how many? I tried <code> vi -c ":g/^$/d | wq" filename </code> but I have to run it several times. This is NOT homework. :) Thanks for your time. (3 Replies)
Discussion started by: Habitual
3 Replies

5. Shell Programming and Scripting

Preserving Empty Lines while Replacing Numbers

Greetings, I am using tcsh to write a script that will replace the numbers in a file with a single number, the caveat is that this file has blank lines which are necessary for another step down the line so I need to preserve the blank lines. I have tried sed and awk but both will collapse the... (1 Reply)
Discussion started by: bonesy
1 Replies

6. Shell Programming and Scripting

expect - How to ignore empty lines?

Hi all, I'm looking for a way to generate an error when a command does not print an expected message. For example : test.sh : echo hi!test.exp : exp_internal 1 spawn ./test.sh expect { "hi!" {puts "bingo!"} "*" {puts "error!" ; exit 1} } I expected test.exp to match the string... (2 Replies)
Discussion started by: whbos
2 Replies

7. Shell Programming and Scripting

Removing empty lines(space) between two lines containing strings

Hi, Please provide shell script to Remove empty lines(space) between two lines containing strings in a file. Input File : A1/EXT "BAP_BSC6/07B/00" 844 090602 1605 RXOCF-465 PDTR11 1 SITE ON BATTERY A2/EXT... (3 Replies)
Discussion started by: sudhakaryadav
3 Replies

8. UNIX for Advanced & Expert Users

How to delete empty lines

abc# abc#this is a test abc#this is a test to delete abc# xyz# xyz#this is a test two xyz# In the above example '#' is common. How to do delete the emply lines. In specific to observe the output as: abc#this is a test abc#this is a test to delete xyz#this is a test two . . . . (5 Replies)
Discussion started by: Aejaz
5 Replies

9. Shell Programming and Scripting

delete multiple empty lines

Hi, I need to delete the lines with empty name. What is the best way to do it? Thanks a lot for your help! EMID MMDDYY HOURS JOB EMNAME 0241 051605 11.40 52062 someone 0520 051605 10.63 52062 0520 051605 10.66 52062 0520 051605 10.65 52062 (3 Replies)
Discussion started by: whatisthis
3 Replies

10. Shell Programming and Scripting

cat and empty lines

Hi , i'm searching for an easy solution to list a file without empty lines , i haven't found with cat and grep ! Anybody has an idea ? thanks in advance christian (4 Replies)
Discussion started by: Nicol
4 Replies
Login or Register to Ask a Question