I’m trying pipe the output of an awk command through more than one command at once in a Bash shell, following my knowledge I’m coming up with this:
awk '$13 ~ /type/ {print $15}' filename.txt | (wc -l || sort -u)
I want the result of the awk command to be both counted AND sorted, how can I accomplish that?
Even with && command it doesn’t work, it does execute the first command and then exits.
I guess it is my knowledge of bash which is failing.
Thanks in advance.
If you want to send output to two different commands in a single line, you’ll need to do process substituion.
Try this:
This outputs the line count on stderr and the sorted output on stdout. If you need the line count on stdout, you can do that leave off the
>&2, but then it will be passed to the sort call and (most likely) sorted to the top of the output.EDIT: corrected description of what happens based on further testing.