[英]How to delete lines containing the pattern `{.*[a-Z0-9《》【】].*}` with sed?
我需要從文件中刪除包含aZ
, 0-9
或符號《
, 》
, 【
或】
中的任何一行的所有行,但前提是必須在括號( {
和}
)內找到它們。同一行。
例如,獲取示例文件:
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.
aZ
項目。 《
存在並且在大括號。 {
和}
大括號之間。 我嘗試制作此BASH腳本,但是在仔細檢查了輸出之后,發現了一些實例,這些實例不起作用:
sed '/{.*[a-Z0-9《》【】].*}/d' input.txt > output.txt
為什么在括號之間發現我的sed
腳本不能正確刪除aZ
, 0-9
, 《
》
, 【
或】
所有行?
您的角色類別不正確[aZ]
。 它應該是[az]
或[AZ]
或都為[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, 《水滸傳》.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.