Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何从包含黑白两行的文件中删除所有具有特定单词的内容?
例如 -
文件:
Outstanding .. dd gd count ... text2 text1 text3 Outstanding .. dd gswrff dddfdd count text3 text4 text5
输出应该是这样的:
text2 text1 text3 text3 text4 text5
如果您只想捕获其中包含单词的行text:
text
grep text < file
或者
sed -n /text/p < file
awk '/text/ { print }' < file
问题不是很清楚。但是,如果您要删除 2 个特定单词之间的文本,那么您可以使用这个 sed 单行:
sed -i.bak '/Outstanding/,/count/d' file
输出: