Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 12-21-2007, 02:10 PM   #1
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;
echo "${line}" | awk '{ print $1 }' | egrep -v "ID|\-";
done < /tmp/coa1.txt > /tmp/coa2.txt

cat /tmp/coa2.txt

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


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
LQ Addict
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
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:
done < /tmp/coa1.txt >> /tmp/coa2.txt
Old 12-21-2007, 03:44 PM   #3
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.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:19 PM.

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