使用awk或cut或perl选择特定的列 [英] Select a particular column using awk or cut or perl

查看:72
本文介绍了使用awk或cut或perl选择特定的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从制表符分隔的文件中选择第7列.例如:

I have a requirement to select the 7th column from a tab delimited file. eg:

cat filename | awk '{print $7}'

问题在于第4列中的数据具有多个值,且中间有空白.示例-以下输出中的最后一行:

The issue is that the data in the 4th column has multiple values with blank in between. example - The last line in the below output:

user  \Adminis FL_vol Design         0         -       1       -
group        0 FL_vol Design   19324481         -    3014       -
user      \MAK FL_vol Design   16875161         -    2618       -
tree       826 FL_vol Out Global Doc Mark     16875162         -    9618       - /vol/FL_vol/Out Global Doc Mark

推荐答案

如果数据明确地用制表符分隔,则cut将在制表符而不是空格处剪切:

If the data is unambiguously tab-separated, then cut will cut on tabs, not spaces:

cut -f7 filename

您当然也可以使用awk来做到这一点:

You can certainly do that with awk, too:

awk -F'\t' '{ print $7 }'

这篇关于使用awk或cut或perl选择特定的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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