While read do, then echo, gives double output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting While read do, then echo, gives double output
# 1  
Old 07-09-2009
While read do, then echo, gives double output

Sorry about the title, but this should be fairly self-explanatory.

My script seems to work, except that in the output, below, the first three lines are correct, but why does it print the additional lines 4, 5, & 6?

Script:
Code:
#!/bin/bash

while read;
do
 client="$(grep -m 1 Client | awk -F" " '{ print $2; }')"
 elapsed="$(grep -m 1 "Elapsed time" | awk -F" " '{ print $3,$4,$5,$6,$7,$8; }')"
 volname="$(grep -m 1 "Volume name" | awk -F" " '{ print $3; }')"

 echo The client name is $client
 echo The elapsed time was $elapsed
 echo The Volume name is $volname

done < /home/mine/bakupresult
exit 0


Result
Code:
The client name is "BaculaServer-fd"
The elapsed time was 1 min 57 secs
The Volume name is 000003L3
The client name is
The elapsed time was
The Volume name is


How can I stop those last 3 lines from being output?

Any help appreciated.
# 2  
Old 07-09-2009
i can only guess you have a blank line at the end of your input file?
# 3  
Old 07-09-2009
Blank line in the file /home/mine/bakupresult.
Give a
Code:
cat -e /home/mine/bakupresult

to check
# 4  
Old 07-09-2009
Thanks guys,

robsonde: Yes there was a blank line at the end. I removed it, but no change. Smilie

dennis.jacob: Thanks for the 'cat -e' command/switch. There is indeed a blank line about 5 lines from the bottom of the input file. This input file is just for testing purposes, the actual input will hopefully come from STDIN, but in exactly the same format as the current input file.

So, is there something that I can add so that blank lines will be ignored?

regards,
Ken
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Printing double quotes in echo command

Please help me to use echo or printf type of command to print some value from variable within double quotes - I want to print the double quote ( " ") also. I tried #!/bin/bash VALUE=some_value echo '{"value" : "$VALUE"}' I was expecting the above script would produce .. {"value" :... (3 Replies)
Discussion started by: atanubanerji
3 Replies

2. Shell Programming and Scripting

How to read each line from input file, assign variables, and echo to output file?

I've got a file that looks like this (spaces before first entries intentional): 12345650-000005000GL140227 ANNUAL HELC FEE EN 22345650-000005000GL140227 ANNUAL HELC FEE EN 32345650-000005000GL140227 ANNUAL HELC FEE EN I want to read through the file line by line,... (6 Replies)
Discussion started by: Scottie1954
6 Replies

3. Shell Programming and Scripting

Double quotes and variable proble in echo

HI Guys, I want to echo below line in my file :- lpd | grep AL | nawk '{print "1dLA - " $0} How can i echo same Output (4 Replies)
Discussion started by: pareshkp
4 Replies

4. Shell Programming and Scripting

How to read in a part of an echo line?

Hello, I have a very basic script #!/usr/bin/ksh while print ' ' print ' 1. View Command History ' print ' 2. List files in current Directory ' read opt'?Enter Option> ' ;do if ;then fc -l fi # if ;then ls -la I want to... (10 Replies)
Discussion started by: Grueben
10 Replies

5. Shell Programming and Scripting

[Solved] echo not updating double quotes in output

Hi , I have a script to update firefox proxy. But the echo is not updating the double quotes. paste /home/names.txt /home/ip.txt | while read i j do mkdir $i echo "user_pref("network.proxy.http", "$j");" >> /home/$i/prefs.js echo "user_pref("network.proxy.http_port", 8080);" >>... (3 Replies)
Discussion started by: ranjancom2000
3 Replies

6. Shell Programming and Scripting

read variable after echo

Hi, i want to create an user-friendly script where you are asked for two numbers. i would like that these two number to be separated with "--" for example, but i can't figure out how to do this. for example read -p "Insert lowest and highest value: " min ; echo -n "-- "; read max so... (3 Replies)
Discussion started by: ezitoc
3 Replies

7. Shell Programming and Scripting

Double echo problem

I'm parsing a router configuration file and printing out some of the fields. Given the following output, I'd like to add the filename to the first column. I'm definately a neophyte in scripting. COUNTER=${#array1 } while ; do ######## echo -n $JUNOS_FILE | ... (3 Replies)
Discussion started by: nocleader
3 Replies

8. Shell Programming and Scripting

Perl echo with double quotes

I need to echo a string that has double quotes in a Perl script. #!/usr/bin/env perl `echo Rule123 -comment \"blah blah\" >> $filename` I'd like to get below appended to $filename: Rule 123 -comment "blah blah" But instead, the double quotes are lost: Rule 123 -comment blah bah ... (1 Reply)
Discussion started by: slchin
1 Replies

9. UNIX for Dummies Questions & Answers

echo appends to a read-only file

echo command can append to a read-only file too. If the file is read-only, with w flag removed, then even echo should not be able to append to the file. But it is possible. Can anybody explain the below behaviour? /root > echo 'sample text' > file /root > cat file sample text /root >... (2 Replies)
Discussion started by: anand_bh
2 Replies

10. Shell Programming and Scripting

how to read a file to an echo statement

I was searching for an option where i can echo some strings together with the contents of a file. Eg. I was to echo the below string to a file "alter application PMS_ add variable CurrYear Y2009;" >> ${ESS_MAXL_DIR}/PMS_SUB.txt The value 2009 is coming from a file called date.txt without the... (3 Replies)
Discussion started by: Celvin VK
3 Replies
Login or Register to Ask a Question