在 linux 中从分隔文件中删除一列 [英] Delete a column from a delimited file in linux
本文介绍了在 linux 中从分隔文件中删除一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个格式如下的文件:
I have a file in the following format:
col1|col2|col3|col4
a|b|c|d
e|f||h
i|j|k|l
我想从标题和数据中删除 col3(带有分隔符|").这可以使用 awk/sed 来完成吗?
I would like to delete col3 (with the delimiter "|") from the header and the data as well. Can this be done using awk/sed?
请注意 col3 中的数据可能为空(第 2 行).
Plese NOTE that the data in col3 maybe empty (row 2).
输出应该是:
col1|col2|col4
a|b|d
e|f|h
i|j|l
推荐答案
你可以简单地使用 cut
.
cut -d'|' -f1-2,4- file
这篇关于在 linux 中从分隔文件中删除一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文