Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

While statement and Pipe

Status
Not open for further replies.

HopeLessGuy

Technical User
Jun 9, 2003
10
US
I currently have a while loop which reads the file till EOF. The file contains file names that are to be searched. In the while statement, I noticed that korn shell does not treat the pipe, | , as it original is used.

For example -

while read tmpFiles
do
i=$i+1
tmpArray=$tmpFiles
fName="${tmpArray}"

grep -c "yo" ${fName%% *} | awk -F: '$2 == 3 { print $1 }'

done < &quot;tmpList.dat&quot;

That's just rushed code, shouldn't be taken into account :p But I noticed, that while the loop executes. It will read the right side of the pipe ( | ) then read &quot;tmpList.dat&quot; then read the left side of the ( | ). Therefore the awk is useless since it doesn't receive the exact information from grep due to the order of execution. If I were to use the grep | awk out of the loop, it works. Any ideas?

 
I don't think the problem stems from execution order or anything odd like that, but because of the grep -c output format.

With multiple files, e.g. grep -c yo file*, it looks like this:

[tt]file1:3
file2:0
file3:3[/tt]

But with a single file, e.g. grep -c yo file1 it looks like this:

[tt]3[/tt]

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top