Cat Command and Blank Lines


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cat Command and Blank Lines
# 1  
Old 02-26-2010
Cat Command and Blank Lines

Hi All,

I was testing for blank lines and I want to use the cat command only

Code:
for groupline in `cat /home/test/group`
do
         if [ -z $groupline ]
    then
        echo "blank found"
    fi 
done

I want to check if the current line read is a blank line.

I have tested with $groupline="\n" , "\r\n" but no use.

Any ideas ?

Last edited by pludi; 02-26-2010 at 06:49 AM.. Reason: code tags
# 2  
Old 02-26-2010
MySQL

Code:
$groupline=  /^$/ ;

It will match only blank line
# 3  
Old 02-26-2010
Have you tried with grep "^$"?
# 4  
Old 02-26-2010
Quote:
Originally Posted by datkan
Hi All,

I was testing for blank lines and I want to use the cat command only
Why? Homework?

The cat command is used to concatenate and display files.

It is mostly unnecessary in conjunction with other commands.
# 5  
Old 02-26-2010
Actually when using the cat command with the for loop it is not at all giving the blank lines

I am having the file "group" with some of the lines as blank also.

I have tried the following code
Code:
for groupline in `cat /home/thillaiselvan/group`
do
        echo $groupline
done

the output I am getting is as follows when executing the above script
hai
hello

So the cat command itself in the above context is not giving the blank lines
# 6  
Old 02-26-2010
Thts right Thillai....

There is an existing code ....I have posted a simplified example here....so I cant change the way the file is read....Is there a way around to test ?

And Franklin , Its not homework Smilie
# 7  
Old 02-26-2010
Using CAT we cannot achieve this
So we can do in this way ( if you prefers )
Code:
while read line
do
        echo -e "$line \n"
         if [ -z $line ]
    then
        echo "blank found"
    fi
done <filename

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To check Blank Lines, Blank Records and Junk Characters in a File

Hi All Need Help I have a file with the below format (ABC.TXT) : ®¿¿ABCDHEJJSJJ|XCBJSKK01|M|7348974982790 HDFLJDKJSKJ|KJALKSD02|M|7378439274898 KJHSAJKHHJJ|LJDSAJKK03|F|9898982039999 (cont......) I need to write a script where it will check for : blank lines (between rows,before... (6 Replies)
Discussion started by: chatwithsaurav
6 Replies

2. UNIX for Advanced & Expert Users

Delete blank spaces and blank lines in a file

Hi Gurus, Somebody can say me how to delete blank spaces and blank lines in a file unix, please. Thank you for advanced. (10 Replies)
Discussion started by: systemoper
10 Replies

3. UNIX for Dummies Questions & Answers

Remove blank lines using cat command

plz help me to figure it out how i remove empty or blank files using cat command. i will be very thankful if u send me this answer... thanks (3 Replies)
Discussion started by: mushfiks1
3 Replies

4. Shell Programming and Scripting

UNIX command to count blank lines in a file in DOS format

Hi Team, The content of the file is as follows. asdf 234 asdf asdf dsfg gh 67 78 The file is in DOS format (not in Unix Format). The file is transferred to Unix. I need a unix command to check the number of blank lines in a input (comming from Windows). If it is greater than... (4 Replies)
Discussion started by: kmanivan82
4 Replies

5. UNIX for Dummies Questions & Answers

Cat command drops lines in output file

I use the cat command to concatenate text files, but one of the rows I was expecting doesn't display in the output file. Is there a verbose mode\logging mechanism for the cat command to help me investigate where the lines I was expecting are going?? cat 7760-001_1_*_06_*.txt | grep -v... (1 Reply)
Discussion started by: Xin Xin
1 Replies

6. Shell Programming and Scripting

Want non-interpretation of blank space using cat

I have a file say ADCD which is like following--> Please consider 'z' as space #cat ADCD <!--Yzzz|z--> <!--Nzzzzz--> Now I want to store the content of this file to a variable say VAR like this--> #VAR=`cat ADCD` #echo $VAR <!--Yz|z--> <!--Nz--> Now I don' t want the variable... (2 Replies)
Discussion started by: muchyog
2 Replies

7. Shell Programming and Scripting

Cat Command on File not printing "Blank" Lines?

Hello All, I have a bash script and in it at some point I call an Expect Script that does some stuff and saves its output in a ".txt" file. Example "/path/to/my/file/Expect_Output.txt" file: notice the 2nd line is empty in the file... Data for Host-1 (192.168.1.110) Checking the... (2 Replies)
Discussion started by: mrm5102
2 Replies

8. Shell Programming and Scripting

Delete blank lines, if blank lines are more than one using shell

Hi, Consider a file named "testfile" The contents of file are as below first line added for test second line added for test third line added for test fourth line added for test fifth line added for test (5 Replies)
Discussion started by: anil8103
5 Replies

9. UNIX for Dummies Questions & Answers

Grep command to remove blank lines

The following grep command grep -v "^$" filename > newfilename does not populate the new file with any data. I see it search the entire input file but the output file never gets filled. Is this not the correct command for what Im looking to do? (2 Replies)
Discussion started by: aispg8
2 Replies

10. Shell Programming and Scripting

cat in the command line doesn't match cat in the script

Hello, So I sorted my file as I was supposed to: sort -n -r -k 2 -k 1 file1 | uniq > file2 and when I wrote > cat file2 in the command line, I got what I was expecting, but in the script itself ... sort -n -r -k 2 -k 1 averages | uniq > temp cat file2 It wrote a whole... (21 Replies)
Discussion started by: shira
21 Replies
Login or Register to Ask a Question