Wednesday, December 8, 2010

Using SED to replace the first string found in file and ignore rest of the strings

The SED command is used to do operations line by line. Suppose you want to change first occurence of a string in file and leave other strings try the below code:

sed -e "0,/oldstringpattern/s/oldstringpattern/newstringpattern/" myfile.xml > temp

Basically the '0' tells SED which occurence need to be replaced. 0 stands for 1st occurence, 1 for 2nd and so on....

No comments:

Post a Comment