我尝试做的是使用sed将所有字符设置为图案右侧的小写字母,但仅限于包含其他图案的行。
我想说我想在包含单词sillyduck的行的/ directory / lowercase右边创建所有内容。
在:
sillyduck MOO/WORD/directory/THIS/FILE.TXT
sillyduck another/directory/with/a/file.DOC
#sillyduck MOO/WORD/directory/ANOTHER/FILE
sillygoose MOO/WORD/directory/THIS/FILE.TXT
SILLYDUCK MOO/WORD/DIRECTORY/THIS/FILE.TXT
sillyduck QUACK/DUCK/directory/You/Get/The/Idea.doc
后:
sillyduck MOO/WORD/directory/this/file.txt
sillyduck another/directory/with/a/file.doc
#sillyduck MOO/WORD/directory/another/file
sillygoose MOO/WORD/directory/THIS/FILE.TXT
SILLYDUCK MOO/WORD/DIRECTORY/THIS/FILE.TXT
sillyduck QUACK/DUCK/directory/you/get/the/idea.doc
这样做的最佳方法是什么?我想坚持使用sed来解决问题。
提前致谢! :)
答案 0 :(得分:3)
鉴于评论中的新信息:
$ echo 'sillyduck MOO/WORD/directory/THIS/directory/FILE.TXT' |
sed '/sillyduck/ s~/directory/.*~\L&~'
sillyduck MOO/WORD/directory/this/directory/file.txt