【发布时间】:2019-11-03 02:04:01
【问题描述】:
我想要打印的内容有几个条件(跳过包含在我想要打印的部分中的 hello,从 \k{f} 打印到 \l{k},从 \word{g} 到 \word2 {g},打印从 \hello2 开始的行并打印 \b 和 \bf 之间的部分 - 有一个问题:在 \bf} 中是不应该打印的}):
awk '
/\\hello/{
next
}
/\\k\{f\}|\\word\{g\}|\\b/{
found=1
}
found;
/\\l\{f\}|\\word2\{g\}|\\bf/{
found=""
}
/\\hello2/
' file.txt
我想为 \bf 添加条件,它应该在行中单独存在。请问该怎么做?
文件.txt:
text
text
\hello2
456
565
\word{g}
s
\hello
\word2{g}
\k{f}
fdsfd
fgs
\l{f}
text
\b
7
\hello
\bf}
text
现在输出:
\word{g}
s
\word2{g}
\k{f}
fdsfd
fgs
\l{f}
\b
7
\bf}
想要的输出:
\word{g}
s
\word2{g}
\k{f}
fdsfd
fgs
\l{f}
\b
7
\bf
此问题与:this question
【问题讨论】:
-
能否在您的问题中更清楚地添加条件,例如-->
I want to print from \k{f} tol{f}` 等?目前还不清楚。 -
我在我的问题中添加了它
-
请不要发布变色龙问题,请参阅meta.stackexchange.com/q/43478/361691。
标签: awk