sed 从开始提取文本到字符串 [英] Sed to extract text from start to string
本文介绍了sed 从开始提取文本到字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的输入:
xxxx1
xxxx2
xxxx3
END
xxxx4
xxxx5
我想要这个:
xxxx1
xxxx2
xxxx3
我试过了.
<<input>> | sed -n '/./,/^END/p' | sed '$d'
但我明白了:
xxxx1
xxxx2
xxxx3
END
xxxx4
它似乎是."这在这里不起作用.
It seems to be the '.' that does not work here.
推荐答案
如果目标是获取所有数据直到 END
和 xxxx
可以通过任何东西,这个 awk
应该这样做:
If the goal is to get all data up until END
and xxxx
can by anything, this awk
should do:
<<input>> | awk '/END/ {exit} 1'
xxxx1
xxxx2
xxxx3
- 如果找到
END
,退出 1
始终为真,既然没有动作,就做默认动作,打印- If
END
is found, exit 1
always true, and since no action, do the default action, print
这篇关于sed 从开始提取文本到字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文