开发者

How can I pass an output file from a AWK script to an argument in cat?

I wish to concatenate file2 with file3 without saving file2 in the disk.

awk开发者_如何学JAVA '...{print}' file1 > file2 

cat file2 file3 > file4 

How can I do it without saving file2?

Thank you for your help


You could use a subshell

(awk '...{print}' file1; cat file3) > file4


I prefer @Peter's answer, but depending on your shell (bash/zsh/...), you could use process substitution:

cat <(awk ...) file3 > file4


You can also use just Awk:

awk FNR file1 file3> file4

This will concenatefile1 and file3 and will save it to file4


You can do it without a subshell:

awk '...{print}' file1 | cat - file3 > file4 

or even:

awk 'FNR!=NR {print;next} ... {do_stuff}' file1 file3 > file4

That will cause file1 to be processed by do_stuff and file3 will be passed straight through.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜