awk gzip output to multiple files

2019-03-03 09:32发布

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"}'

标签: awk gzip
2条回答
三岁会撩人
2楼-- · 2019-03-03 10:10

Using awk, it can handle more columns easily.

echo "col1 col2" | awk '{for (i=1;i<=NF;i++) print $i | "gzip > out" i ".gz"}'
查看更多
贼婆χ
3楼-- · 2019-03-03 10:21

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"}'
查看更多
登录 后发表回答