从文件中删除最后3列 [英] delete last 3 columns from a file

查看:68
本文介绍了从文件中删除最后3列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含6列的文本文件.如何从此文件中删除最后三列?

I have a text file with 6 columns. How can I delete the last three columns from this file?

c1  c2  c3  c4  c5   c6

所需的输出

c1  c2  c3

推荐答案

您可以使用@paxdiablo的awk减小NF

You can use @paxdiablo's awk to reduce the value of NF

或者您可以使用sed

sed 's/\([ \t]\+[^ \t]*\)\{3\}$//' your_file

如果您使用的是Linux,则GNU sed提供-r

If you are on Linux, GNU sed provides -r

sed -r 's/([ \t]+[^ \t]*){3}$//' your_file

这篇关于从文件中删除最后3列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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