从Linux中分隔的文件删除列 [英] Delete a column from a delimited file in linux
本文介绍了从Linux中分隔的文件删除列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下格式的文件:
COL1 | COL2 | COL3 | COL4
A | B | C | D
Ë| F || ^ h
我|百灵| K | L
我想删除COL3(与分隔符|)从报头和数据,以及。可以这样用awk做/ sed的?
普莱舍注意,在COL3数据可能为空(行2)。
输出应该是:
COL1 | COL2 | COL4
A | B | D
Ë| F | H
我|百灵| L
解决方案
您可以简单地使用剪切
。
切-d'|' -f1-2,4-文件
I have a file in the following format:
col1|col2|col3|col4
a|b|c|d
e|f||h
i|j|k|l
I would like to delete col3 (with the delimiter "|") from the header and the data as well. Can this be done using awk/sed?
Plese NOTE that the data in col3 maybe empty (row 2).
The output should be:
col1|col2|col4
a|b|d
e|f|h
i|j|l
解决方案
You could simply use cut
.
cut -d'|' -f1-2,4- file
这篇关于从Linux中分隔的文件删除列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文