2

I need to replace a string in a file with another string, but before the replacement I need to lowercase the new string before passing it to sed.

echo 'NEWSTRING' | tr '[:upper:]' '[:lower:]' | sed 's/foo/(my tr output in lowercase)/g' file.txt

My question is, How we could pass the replacement string as a parameter ?

4

3 に答える 3

4

Try using xargs, e.g.:

echo 'NEWSTRING' | tr '[:upper:]' '[:lower:]' | xargs -I '{}' sed 's/foo/{}/g' file.txt
于 2012-10-12T09:03:36.880 に答える
4
sed "s/foo/$(echo .. |tr ...)/g" file.txt
于 2012-10-12T09:04:39.217 に答える
3

This might work for you (GNU sed):

sed 's/foo/\L'"NEWSTRING"'/'g file
于 2012-10-13T06:14:14.667 に答える