【发布时间】:2017-02-22 01:06:50
【问题描述】:
我尝试了以下各种组合:
awk -F" ||| " '{$0=$1}1' source_file.txt > column1.txt
awk -F" ||| " '{$0=$1}2' source_file.txt > column2.txt
或
awk 'BEGIN {FS=" ||| ";}{print $1}' source_file.txt > column1.txt
awk 'BEGIN {FS=" ||| ";}{print $2}' source_file.txt > column2.txt
我要么得到整行(例如foo bar ||| baz),要么只得到第一个单词(例如foo),而不是所需的输出。
如果您愿意提供帮助,这里有一个示例文本文件:
source_file.txt
foo bar ||| baz
qux ||| quux
corge grault ||| garply waldo
fred |||
xyzzy ||| thud
这是所需的输出:
column1.txt
foo bar
qux
corge grault
fred
xyzzy
column2.txt
bar
quux
garply waldo
thud
【问题讨论】:
标签: linux awk sed text-manipulation