Reputation: 5972
I am going to ask about a structure about pipes with while loops within parentheses.
Imagine I have a script like this:
#!/bin/bash
<FirstCommand> | (while read var1; do out=`echo $var1 | <command>` \
<sth with $out> done; awk -v RS="" '{print $5,$18,$20}' OtherFile | awk 'NF==3{print}{}' | awk '{gsub (/<blank>/,""); print}' > file.txt \
while read var2 var3 var4; do <sth> done < file.txt)
The point is my script is working correctly till end of first while loop. but the second one has a problem.
My question:
Is the output of my FirstCommand
redirecting to both while loops simultaneously?
About FirstCommand
:
This is a command that generates some texts and I want to redirect the output of that to while loops run time.
UPDATE
The output of is appending to OtheFile
that awk
is using.
Thank you
Upvotes: 0
Views: 1581
Reputation: 1330
Try something like
<FirstCommand> | tee FirstCommand.output | (while read var1; do out=`echo $var1 |<command>` <sth with $out> done; awk -v RS="" '{print $5,$18,$20}' $NmapOut | awk 'NF==3{print}{}' | awk '{gsub (/<blank>/,""); print}' > file.txt; cat FirstCommand.output | while read var2; do <sth> done < file.txt)
where FirstCommand.output
is a temporary file that will contain the output of <FirstCommand>
.
Upvotes: 1
Reputation: 212248
The output of the first command is being sent to the input of the shell which contains the two loops. The first loop consumes all of the data. The input of the second loop is the file file.txt ( the output of the awk
. Unless there is some reason not shown here, you might as well pipe the awk directly to the second while loop.)
Upvotes: 1