【发布时间】:2026-02-12 05:20:06
【问题描述】:
带有制表符分隔字段的输入文件#1:
one two three four five six four
one two three four five six four
one two three four five six four
case1:我需要从每一行中删除所有包含字符串的字段,例如 four 并获得仍然单个 TAB 分隔的剩余字段。
case2:我需要删除第 n 列,并为输出中的剩余字段保留一个 TAB 分隔符,但在这里我得到了多个 TAB:
$ echo -e "one\ttwo\tthree\tfour\tfive\tsix\tfour\none\ttwo\tthree\tfour\tfive\tsix\tfour\none\ttwo\tthree\tfour\tfive\tsix\tfour"|awk -F"[\t]" '{$3="";$5=""}{print $0}' OFS='\t'
one two four six four
one two four six four
one two four six four
我可以通过tr -s '\t' 发送输出来修复它,但是如何修改awk 以避免tr 命令?
【问题讨论】:
-
所以你期待
one|two|four|six|four? -
抱歉,我从描述中删除了误导性内容。我需要在输出上使用单个 TAB 分隔字段。
-
没有什么是误导。我所说的单个管道也指单个选项卡。