So, first, the awk on line 1 reads and discards the first two lines from sample.txt and writes the last two lines from sample.txt into the pipe feeding line 2.
The read on line 2 sets Dep to 1001|3252 (consuming the 3rd line from sample.txt that was the 1st line output by the awk on line 1).
Then (since no other input file is specified) the awk on line 3 reads the remainder of the output from the awk on line 1 and prints 1002 .
Then the next call to read on line 2 hits EOF and terminates the while loop.
If you want the awk on line 3 to process the data stored in $Dep , you could change your script to something like:
I assumed machomaddy plans to perform other processing on each (non-header) line of an input file and that the second awk was a placeholder for some other processing.
If all that machomaddy wants is to print up to the first vertical bar in every line after line 2 from an input file:
Thanks Don!! your explanation was much appreciated. I realized the fault...I posted the correct code just before your 1st reply
You were right, I had few operations to be performed in the second awk!!!
Unless you have other things that have to be done by something other than awk between your calls to awk, it would be much more efficient to do all of the work in a single awk script rather than calling awk n-1 times (where n is the number of lines in your input file).