[英]Delete header/column from .txt file with bash
I'm automating a workflow with a bash script on Mac OSX.我正在 Mac OSX 上使用 bash 脚本自动化工作流程。 In this workflow, I'd like to add a command that deletes a header from my table (.txt) file that is tab delimited.在此工作流程中,我想添加一个命令,该命令从我的表 (.txt) 文件中删除以制表符分隔的标题。 It looks as follows:它看起来如下:
header1 header2 header3
a 1
b 2
c 3
d 4
e 5
f 6
As you can see, the third column, named header3
, is empty.如您所见,名为header3
的第三列是空的。
I've noted this post or this one but I don't understand the arguments.我已经注意到这个帖子还是这一个,但我不明白的论点。
Could you suggest a line of code that automatically deletes the third column, or (even better) deletes the header called 'header3'?您能否建议一行自动删除第三列的代码,或者(甚至更好)删除名为“header3”的标题?
我找到了答案在这里表2C。
sed s/header3//g input.txt > output.txt
awk
旨在处理以空格分隔的文本列:
awk '{print $1 "\t" $2}' input.txt > output.txt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.