删除使用awk或SED列 [英] delete a column with awk or sed

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

问题描述

我有三列的文件。我想删除第3列(就地编辑)。我怎样才能做到这一点使用awk或sed的?

  123 ABC 22.3
453 ABG 56.7
1236 HJG 2.3

所需的输出

  123 ABC
453 ABG
1236 HJG


解决方案

这可能会为你工作(GNU SED):

  SED -i -r的/ \\ s + // 3'文件

如果您想第三场之前删除空白:

  SED -i -rS /(\\ S +)?\\ S + // 3'文件

I have a file with three columns. I would like to delete the 3rd column(in-place editing). How can I do this with awk or sed?

123   abc  22.3
453   abg  56.7
1236  hjg  2.3

Desired output

123  abc
453  abg
1236 hjg 

解决方案

This might work for you (GNU sed):

sed -i -r 's/\S+//3' file

If you want to delete the white space before the 3rd field:

sed -i -r 's/(\s+)?\S+//3' file

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

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