如果我有一个文件test.txt:
example 1 content 2013-3-8:
hello java
example 2 content 2013-4-9:
hello c如何使用awk或sed将test.txt分离为两个文件
test1
hello javatest2
hello c我使用以下命令:
awk '/example/{i++}{print > "test"i}' test.txt但是它仍然是第一行(例如xxx),我可以在awk中的print中添加一些片段来删除第一行吗?
发布于 2013-10-29 05:56:47
你几乎拥有它:
awk '/^example/ { i++; next } { print >"test"i}'next使awk跳过其余的语句。
发布于 2013-10-29 05:47:14
您可以使用getline跳过第一行。以下内容应提供所需的输出:
awk '/example/{getline; i++}{print > "test"i}' test.txt发布于 2013-10-29 08:04:49
用sed做这件事的一些奇怪方法:
sh <<< $(sed '/example/{N;s/\n//;s/example \([0-9]*\).*:\(.*\)/echo "\2" >> test\1;/}' input)https://stackoverflow.com/questions/19650580
复制相似问题