使用剪切命令来删除多个列 [英] using cut command to remove multiple columns

查看:98
本文介绍了使用剪切命令来删除多个列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定的输入


 echo 1,2,3,4,5,6,7,8,9,...100 

如果我要砍我可以做5列

If I want to cut columns 5 I can do


cut -d, -f-4,6-

如果我希望削减多个不连续的列像5,7,等什么
有没有一个班轮?

what if I want to cut multiple non consecutive columns like 5, 7,etc is there a one liner?

推荐答案

您应该能够直接继续在现有的 -f 规范中的序列。

You should be able to continue the sequences directly in your existing -f specification.

要跳过两个5和7,请尝试:

To skip both 5 and 7, try:

cut -d, -f-4,6-6,8-

正如你跳过单个顺序列中,这也可以写为:

As you're skipping a single sequential column, this can also be written as:

cut -d, -f-4,6,8-

要继续下去,如果你想跳过5,7,11,你可以使用:

To keep it going, if you wanted to skip 5, 7, and 11, you would use:

cut -d, -f-4,6-6,8-10,12-

要放到一个更明确的观点,这是容易当你使用开始/结束而走在序列列表的开始/结束列,分别进行可视化。例如,下面将打印列2至20中,跳过5和7:

To put it into a more-clear perspective, it is easier to visualize when you use starting/ending columns which go on the beginning/end of the sequence list, respectively. For instance, the following will print columns 2 through 20, skipping 5 and 7:

cut -d, -f2-4,6-10,12-20

所以,这将打印2至4,跳过5,6至10,跳过11,然后在12到20。

So, this will print "2 through 4", skip 5, "6 through 10", skip 11, and then "12 through 20".

这篇关于使用剪切命令来删除多个列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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