提取从多个文件列到命令行一个输出文件 [英] Extracting columns from multiple files into a single output file from the command line

查看:76
本文介绍了提取从多个文件列到命令行一个输出文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有10列的制表符分隔的数据文件。使用AWK,很容易提取柱7,例如,和输出到一个单独的文件。 (请参见这个问题,例如。)

Say I have a tab-delimited data file with 10 columns. With awk, it's easy to extract column 7, for example, and output that into a separate file. (See this question, for example.)

如果我有5个这样的数据文件,我想从他们每个人提取柱7,做一个新文件,5数据列,每个输入文件的第7列?这可以从使用​​awk等命令在命令行做了什么?

What if I have 5 such data files, and I would like to extract column 7 from each of them and make a new file with 5 data columns, one for the column 7 of each input file? Can this be done from the command line with awk and other commands?

或者我应该只是写了一个Python脚本来处理呢?

Or should I just write up a Python script to handle it?

推荐答案

的awk'{A [FNR] = A [FNR]$ 7} END {为(i = 0; I< FNR ;我++)打印[I]}

A 阵列拥有不同的文件中每行

a array holds each line from different files

FNR 在当前输入文件读取记录,在每个文件的开始时设为零数。

FNR number of records read in current input file, set to zero at begining of each file.

END {为(i = 0; I< FNR;我++)打印[I]} 打印数组的内容 A 文件结束

这篇关于提取从多个文件列到命令行一个输出文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆