ignoring blank line in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ignoring blank line in a file
# 1  
Old 11-12-2008
ignoring blank line in a file

i have a file called Cleaner1.log . This files have some blank lines also.My requirement is that it should ignore the blank lines and give me the lines that contain some data.

I m using this logic in a script:

below the contents of file :

Maximum Time Taken for Processing(Failed) RR Message with DB Read : 0 ms
Minimum Time Taken for Processing(Failed) RR Message with DB Read : 0 ms
Maximum Time Taken for Processing(Successful) RR Message without DB Read : 1608 ms
Minimum Time Taken for Processing(Successful) RR Message without DB Read : 1 ms
Average Time Taken for Processing(Successful) RR Message without DB Read : 25 ms
Maximum Time Taken for Processing(Failed) RR Message without DB Read : 2897 ms
Minimum Time Taken for Processing(Failed) RR Message without DB Read : 2 ms
Average Time Taken for Processing(Failed) RR Message without DB Read : 11 ms
***** Completed Execution Summary *****

--------------------------------------------------------------------------

after the line "***** Completed Execution Summary *****" there is another line (i.e. last line ) which is totally blank,so when i gave the below command it shows the value as 1

cat Cleaner1.log | tail -1 | wc -l---------->1

i want whenever i do tail and if the last line is blank line it should give me the count as 0

plz help me in this ?
# 2  
Old 11-12-2008
in both ways if you wrote tail -1 | wc -l, the answer will always be one.

What do u want exactly, do you want to know if the last line is empty ?
# 3  
Old 11-12-2008
yes if the last line in empty/blank then the count should be zero and then i can go ahead with my rest of the script.

i just want if the last line in empty/blank then the count=0
# 4  
Old 11-12-2008
still "\n" (last line) will be counted as 1 character, so I think you need
so if it's new empty line.. wc -m should equal to 1

tested on #! /bin/sh

if ((`cat Cleaner1.log | tail -1 | wc -m` == 1))

then
echo " last line is empty"

fi

Hope I understood your problem.
# 5  
Old 11-12-2008
i got the problem solve with the below command. hope this is feasible

tail -1 Cleaner1.log | grep -v "^$" | wc -l---------> 0
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Deleting the last non blank line from a file

PGW|PGW_CDR_|2017-06-23 141946|2017-07-17 131633|2017-08-21 PGW|PGW_CDR_|2017-06-23 141946|2017-07-17 131633|2017-08-21 PGW|PGW_CDR_|2017-06-23 141946|2017-07-17 131633|2017-08-21 PGW|PGW_CDR_|2017-06-23 141946|2017-07-17 131633|2017-08-21 PGW|PGW_CDR_|2017-06-23 141946|2017-07-17... (6 Replies)
Discussion started by: swathi reddy1
6 Replies

2. Shell Programming and Scripting

In a file, replace blank line by the last line not blank above

Dear All, In a CSV file, say that a given column has been extracted. In that column, information is missing (i.e. blank lines appear). I would like to replace the blank lines by the last valid line (not blank) previously read. For example, consider the extract below: 123 234 543 111... (7 Replies)
Discussion started by: bagvian
7 Replies

3. Shell Programming and Scripting

Delete blank line in regular file

Hi all, I have file1 with line blank e.g. $cat file1 aaa 111 222 333 444 bbb 555 666 777 888 ccc ddd 1010 1010 1010 eee then i need delete the lines blank (3 and 5) so show $cat file1 aaa 111 222 333 444 bbb 555 666 777 888 ddd 1010 1010 1010 (5 Replies)
Discussion started by: aav1307
5 Replies

4. Shell Programming and Scripting

Insert blank line in a file

I have a file with data as below : Heading 1 ------------- Heading 1 data1 Heading 1 data2 Heading 1 data3 Heading 1 data4 Heading 2 ------------- Heading 2 data1 Heading 2 data2 Heading 2 data3 Heading 2 data4 Heading 3 ------------- Heading 3 data1 Heading 3 data2 Heading 3... (2 Replies)
Discussion started by: yoursdivu
2 Replies

5. Shell Programming and Scripting

Replace two blank line with a single blank line

Hi Guys, I have a file in which each set of records are separated by two blank line. I want to replace it with a single blank line. Can you guys help me out? Regards, Magesh (9 Replies)
Discussion started by: mac4rfree
9 Replies

6. Shell Programming and Scripting

how to replace a line in file with blank line

Hi I nned cmd to which will help me to replace a line in file with blank line e.g. file1 a b c d e after running cmd I shud get file1 b c d e (5 Replies)
Discussion started by: tarunn.dubeyy
5 Replies

7. Shell Programming and Scripting

How to extract a string from a file ignoring new line

Hi, sumdays before i had posted a query with same subject. i got sum great help from great ppl which solved my problem then. But now there is a small problem with the code that i need the experts help upon. for parsing a text like this where $ had been the delimiter between... (3 Replies)
Discussion started by: suresh_kb211
3 Replies

8. Shell Programming and Scripting

how to get the blank line number of a file?

I want to get the blank line number of a file. example: 9000|9000|WW|1|1|SL|472|472|LC|2272|1072|MTY|niceDay 9000|9000|WW|1|1|SL|470|470|MC|1270|1172|MPVT|nice 9000|9000|WW|1|1|SL|472|472|LC|1072|1672|MBD|Sonice 9000|9000|WW|1|1|SL|473|473|LF|1173|1173|MTY|nice666 I want to get... (5 Replies)
Discussion started by: robbiezr
5 Replies

9. Shell Programming and Scripting

Remove last blank line of file

I have a number of files (arranged in directories) which have last line blank, I am trying to synchronize my code with other env and due to this blank lines, all files error out as different although only difference is that of balnk line at end of file. Is there a way I can recursively... (2 Replies)
Discussion started by: ruchimca
2 Replies

10. Shell Programming and Scripting

how to delete a first blank line from the file

I have a file which has the first blank line: sundev22$cat /t1/bin/startallocs /t1/bin/startallocsys 123 sundev22$ Is there a command to remove this first blank line? Thanks for help -A (4 Replies)
Discussion started by: aoussenko
4 Replies
Login or Register to Ask a Question