Linux 如何从多个文件中剪切多列并将输出打印到不同的文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11049748/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to cut multiple columns from several files and print the output to different files
提问by user1458512
I have several files and I only want to take specific columns from it. At the moment, I am using the following code:
我有几个文件,我只想从中获取特定的列。目前,我正在使用以下代码:
$cut -f 1,2,5 AD0062-C.vcf > cutAD0062.txt
However, to speed up the process I was wondering if I could cut the same columns (fields 1,2,5) in multiple files and then print the output to several different files. I.e columns 1,2,5 of files AD0063-C.vcf, AD0064-C.vcf, AD0065-C.vcf should output results to separate files: cutAD0063.txt, cutAD0064.txt, cutAD0065.txt?
但是,为了加快该过程,我想知道是否可以在多个文件中剪切相同的列(字段 1、2、5),然后将输出打印到几个不同的文件。即文件 AD0063-C.vcf、AD0064-C.vcf、AD0065-C.vcf 的第 1、2、5 列应将结果输出到单独的文件:cutAD0063.txt、cutAD0064.txt、cutAD0065.txt?
采纳答案by kev
You can write a for...loop:
你可以写一个 for... 循环:
for i in AD*-C.vcf
do
cut -f 1,2,5 $i > cut${i%-C.vcf}.txt
done