我需要删除包含a-Z
,0-9
或符号《
,》
,【
或{{1}的所有行}来自文件,但只有在大括号(】
和{
)内的某处找到它们,也可以在同一行找到。
例如,取样本文件:
}
Once {upon} a time, there lived an owl.
The owl lived in a {forest with 10,000 trees.}
One day, the owl said, "I like to eat mice."
So the owl ate {10,000} mice.
The owl said, {“吃饱了!”}
Then{,} the owl rested.
The next day, he read the book, 《水滸傳》.
He enjoyed it so much, that he read {《水滸傳》} again the next day.
的项目位于大括号之间。a-Z
存在并且在大括号内。 《
和{
括号之间。我尝试制作这个BASH脚本,但在仔细检查输出后,找到了一些不起作用的实例:
}
为什么我的sed '/{.*[a-Z0-9《》【】].*}/d' input.txt > output.txt
脚本无法正确删除包含sed
,a-Z
,0-9
,《
,》
的所有行,或者在大括号之间找到【
答案 0 :(得分:1)
您的角色类不正确[a-Z]
。它应该是[a-z]
或[A-Z]
或两者[a-zA-Z]
。
sed '/{[^}]*[a-zA-Z0-9《》【】][^}]*}/d' file
$ cat file
Once {upon} a time, there lived an owl.
The owl lived in a {forest with 10,000 trees.}
One day, the owl said, "I like to eat mice."
So the owl ate {10,000} mice.
The owl said, {“吃饱了!”}
Then{,} the owl rested.
The next day, he read the book, 《水滸傳》.
He enjoyed it so much, that he read {《水滸傳》} again the next day.
$ sed '/{[^}]*[a-zA-Z0-9《》【】][^}]*}/d' file
One day, the owl said, "I like to eat mice."
The owl said, {“吃饱了!”}
Then{,} the owl rested.
The next day, he read the book, 《水滸傳》.