LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-21-2007, 02:10 PM   #1
steven.c.banks
Member
 
Registered: Dec 2007
Location: Virginia
Distribution: RHEL
Posts: 44
Blog Entries: 1

Rep: Reputation: 15
Question while read line do done problem


I have the following in one of my scripts:

su - dcmbox -c "dcsca list" > /tmp/coa1.txt

while read line;
do
echo "${line}" | awk '{ print $1 }' | egrep -v "ID|\-";
done < /tmp/coa1.txt > /tmp/coa2.txt

cat /tmp/coa2.txt

while read line
do
/root/robert/compare_one_cos_lab_mc1_mc2.sh $line
done < /tmp/coa2.txt

exit

The first while-do-done loop works as expected, but the second loop runs only once, even though there are numerous lines in /tmp/coa2.txt. I suspect the script I'm calling from that loop is changing the end of file indication; how do I prevent it from doing that?

Thanks in advance...
 
Old 12-21-2007, 03:13 PM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
Code:
done < /tmp/coa1.txt > /tmp/coa2.txt
Each time this line executes, it overwrites coa2.txt, so you end up with only the last line. What you want to do is append to that file, not overwrite it. Change it to this:
Code:
done < /tmp/coa1.txt >> /tmp/coa2.txt
 
Old 12-21-2007, 03:44 PM   #3
steven.c.banks
Member
 
Registered: Dec 2007
Location: Virginia
Distribution: RHEL
Posts: 44

Original Poster
Blog Entries: 1

Rep: Reputation: 15
while read line do done problem

Thanks. However as I mentioned the first loop works fine, and /tmp/coa2.txt has numerous lines in it. Anyway, I made the change you suggested but it did not fix the problem.
The problem I'm having is with the second loop, not the first.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash shell script read file line by line. Darren[UoW] Programming 57 04-17-2016 06:07 PM
BASH: read every line in the files and use the line as parameters as another program tam3c36 Programming 10 12-07-2010 01:42 PM
php - Read file line by line and change a specific line. anrea Programming 2 01-28-2007 01:43 PM
read line by line form text file in java. spank Programming 1 10-18-2006 02:46 PM
linux scripting help needed read from file line by line exc commands each line read atokad Programming 4 12-26-2003 10:24 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration