[英]How to automate linux cut command using bash
Let suppose I have a text file having 4
column and I have to cut every single column and save it into another text file. 假设我有一个包含4
列的文本文件,并且必须剪切每一列并将其保存到另一个文本文件中。 Manually I can do this by the following Linux command but I want to automate this process using bash script. 我可以通过以下Linux命令手动执行此操作,但是我想使用bash脚本自动执行此过程。 Can someone help me with this 有人可以帮我弄这个吗
cut textfile.txt | cut -d ":" -f1 > output1.txt
cut textfile.txt | cut -d ":" -f2 > output2.txt
cut textfile.txt | cut -d ":" -f3 > output3.txt
cut textfile.txt | cut -d ":" -f4 > output4.txt
Textfile.txt Textfile.txt
"text1":"text2":"text3":"text4" "text1":"text2":"text3":"text4" "text1":"text2":"text3":"text4" "text1":"text2":"text3":"text4" "text1":"text2":"text3":"text4" "text1":"text2":"text3":"text4" "text1":"text2":"text3":"text4" "text1":"text2":"text3":"text4" "text1":"text2":"text3":"text4" “ text1”:“ text2”:“ text3”:“ text4”“ text1”:“ text2”:“ text3”:“ text4”“ text1”:“ text2”:“ text3”:“ text4”“ text1”:“ text2“:” text3“:” text4“” text1“:” text2“:” text3“:” text4“” text1“:” text2“:” text3“:” text4“” text1“:” text2“:” text3 “:” text4“” text1“:” text2“:” text3“:” text4“” text1“:” text2“:” text3“:” text4“
col 1 should store in output1.txt "text1" "text1" "text1" "text1" "text1" "text1" "text1" "text1" "text1" col 2 should store in output2.txt "text2" "text2" "text2" "text2" "text2" "text2" "text2" "text2" "text2" col 3 should store in output3.txt "text3" "text3" "text3" "text3" "text3" "text3" "text3" "text3" "text3" col 4 should store in output4.txt "text4" "text4" "text4" "text4" "text4" "text4" "text4" "text4" "text4"
假设您问题中的每个grep textfile.txt
都是cat textfile.txt
(如果是Google UUOC的话),那么您所需要做的就是:
awk -F':' '{for (i=1; i<=NF; i++) print $i > ("output"i".txt")}' textfile.txt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.