我有一个带有类似内容的文件
toto
titi
miam mian
hello
#hello
etc...
我尝试在Toto和Hello之间提取文本我使用:
sed -n '/toto/,/hello/p'
它有95%的时间工作,但是碰巧文件没有相同的语法,并且文本具有
#hello
hello
或
# Hello
Hello
或不同的变量,但仍在匹配模式之前注释这是我的问题:是否有可能对SED说,如果他匹配模式你好,他还必须检查这种模式是否包含特殊的字符,而这一刻才能转到下一个匹配的模式?(不可能将 ^Hello放置,因为有时之前有一个随机数的空间)
因此结果应为
toto
titi
miam mian
# hello
hello
etc...
预先感谢您的答案:)
sed -n '/^ *totob/,/^ *hellob/p' file.txt
允许这样的file.txt这样:
ppp
totox
toto
titi
miam mian
# hello
XhelloW
hello
ppp
和打印
toto
titi
miam mian
# hello
XhelloW
hello
我想我找到了一个解决方案,我做了一个:
cat file.txt | grep -v "#" | sed -n '/toto/,/hello/p'
看起来像这样的好:)