parricc
parricc

Reputation: 89

sed: make everything on matched lines lowercase to the right of a pattern

What I'm trying to do is to use sed to make all characters lowercase to the right of a pattern, but only on lines that contain another pattern.

Let's say I want to make everything to the right of /directory/ lowercase on lines that contain the word sillyduck.

Before:

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

After:

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

What would be the best way to go about doing this? I would like to stick to sed for the solution.

Thanks in advance! :)

Upvotes: 0

Views: 65

Answers (1)

Ed Morton
Ed Morton

Reputation: 203684

Given the new info in your comment:

$ echo 'sillyduck MOO/WORD/directory/THIS/directory/FILE.TXT' |
    sed '/sillyduck/ s~/directory/.*~\L&~'
sillyduck MOO/WORD/directory/this/directory/file.txt

Upvotes: 3

Related Questions