【发布时间】:2013-07-27 11:30:21
【问题描述】:
我的 linux 系统上有一个文件 test.txt,其中包含以下格式的数据:
first second third fourth 10
first second third fourth 20
fifth sixth seventh eighth 10
mmm nnn ooo ppp 10
mmm nnn ooo ppp 20
我需要修改格式如下 -
first second third fourth 10 20
fifth sixth seventh eighth 10 0
mmm nnn ooo ppp 10 20
我试过下面的代码
cat test.txt | sed 'N;s/\n/ /' | awk -F" " '{if ($1~$5){print $1" "$2" "$3" "$4" "$8} else { print $0 }}'
但这并没有提供所需的输出。当有一行下面没有类似的行时,此命令将失败。你能建议我解决这个问题吗?
【问题讨论】: