Scripting- sed command - replacing strings excluding the lines matching a pattern(s)
Hi,
I am having difficulty in using the sed command for finding and replacing strings in a file.
My requirement was to replace all the strings matching a pattern except in lines containing a specific pattern.
Used the below command for this.
sed "/$EXCLUDING_PATTERN/!s/$FIND_STRING/$REPLACE_STRING"
This one worked - it replaced all occurances of $FIND_STRING with $REPLACE_STRING except in lines where $EXCLUDING_PATTERN was found.
I wanted to extend this to multiple exclude patterns - say lines containing any of these patterns $EXCLUDE_PATTERN1, $EXCLUDE_PATTERN2...etc should be ignored while replacing.
Please can somebody help me get the command right for the above requirement?
|