Article 520WJ Piping AWK to multiple separate processes

Piping AWK to multiple separate processes

by
Turbocapitalist
from LinuxQuestions.org on (#520WJ)
If I have an input file with 14 non-blank lines, grouped into two multi-line records, and gawk,

Code:cat in.txt
START
10427
12216
351
5396
2810
END
START
29511
15101
23899
9327
3525
END

awk --version | head -n 1
GNU Awk 5.0.1, API: 2.0 (GNU MPFR 4.0.2, GNU MP 6.2.0)then how can I pipe each record separately?

For example, the following gives a single line count when using the data above but I am looking for a way for it to show two line counts instead:

Code:cat in.txt \
| awk '$1{c++; print c,RS,$0 |"wc -l";}' RS='^START'What seems to be happening is that only one instance of wc is invoked and it gets all the pipe action. I am looking for a way for each record to invoke a separate wc process.

I've tried closing the pipe after each print, but that seems to have no effect. I've also tried using process substitution:

Code:wc -l < <(cat in.txt | awk '$1{c++; print c,RS,$0}' RS='^START')But that seems to give the same result.latest?d=yIl2AUoC8zA latest?i=E7ZdbkTz1tk:RUCMSwnzm-s:F7zBnMy latest?i=E7ZdbkTz1tk:RUCMSwnzm-s:V_sGLiP latest?d=qj6IDK7rITs latest?i=E7ZdbkTz1tk:RUCMSwnzm-s:gIN9vFwE7ZdbkTz1tk
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments