Saturday, May 23, 2020

How to redirect the output of a command that reads a here document to another command in a shell script?

I wrote a long title here, "how to redirect the output of a command that reads a here document to another command in a shell script?"

I found this Stack Overflow post answers this question very well.
Following the answer over there, Below is an example,
{
 cut -d':' -f2 << END
A1: 3
A2: 4
A3: 1
A4: 3 
END
} | awk 'BEGIN {s=0;} {s+=$1;} END {print "sum =", s;}'

No comments:

Post a Comment