Issue
I have a big file which has the word TITLE and the near word the name . So, for example :
cat file1 :
NAME('SAM') SURNAME('WILLIAMS') PASWD('SAMWIL') TITLE('QA')
NAME('JOHN') SURNAME('ROGERS') PASWD('ROGJH') TITLE('QA')
NAME('MATT') SURNAME('JERRY') GRP('ONE') TITLE('RN') PASWD('JERMAT')
NAME('TEST2') SURNAME('NAZ') GRP('TWO') AUTH(USE) TITLE('DEV') GRP('ONE')
I am trying to substitute all TITLE(...) to TITLE('DEV') . So, the output should be :
cat file1 :
NAME('SAM') SURNAME('WILLIAMS') PASWD('SAMWIL') TITLE('DEV')
NAME('JOHN') SURNAME('ROGERS') PASWD('ROGJH') TITLE('DEV')
NAME('MATT') SURNAME('JERRY') GRP('ONE') TITLE('DEV') PASWD('JERMAT')
NAME('TEST2') SURNAME('NAZ') GRP('TWO') AUTH(USE) TITLE('DEV') GRP('ONE')
I just used sed to grep the TITLE and everything after :
sed 's/.*\(TITLE...\)/\1/' file1
Not sure how to substitute the TITLE part . Any help is appreciated, thank you.
Solution
For given format, this would do:
sed -e "s#\(TITLE('\)[^']\+')#\1DEV')#" file1
Actually This may be a bit easier to parse:
sed -e "s#\<TITLE('[^']\+')\>#TITLE('DEV')#" file1
And we do not really save ourselves that much typing with the back reference.
You find any instance of TITLE('<CHARS_NOT_APOSTROPHE>')
(I've also added word edges for a good measure.) and replaces it with TITLE('DEV')
.
Answered By - Ondrej K. Answer Checked By - David Marino (WPSolving Volunteer)