Question

I can gzip an awk output like this:

echo "col1 col2" | awk '{print $1}' | gzip > out

But is it also possible to pipe two awk output file streams to gzip? This doesn't work:

echo "col1 col2" | awk '{print $1 | gzip > "out1.gz"; print $2 | gzip > "out2.gz"}'
Was it helpful?

Solution 2

Using awk, it can handle more columns easily.

echo "col1 col2" | awk '{for (i=1;i<=NF;i++) print $i | "gzip > out" i ".gz"}'

OTHER TIPS

It is, and I found the correct syntax, when searching for awk pipe output:

echo "col1 col2" | awk '{print $1 | "gzip > out1.gz"; print $2 | "gzip > out2,gz"}'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top