Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pattern substuitution idea solution required.

Status
Not open for further replies.

rao12

IS-IT--Management
Jan 10, 2001
9
0
0
US
Hi,
I have a set of files and i need to substitute an existing pattern with a new one.
I have used sed to do the simple substitution.
sed -e 's/Old/New/g' file_name > new_file
But it is case sensitive. I have a set of files which are having a different case for the pattern.
Can anyone let me know how to go aboutt so that i can substitute even if the old pattern is in a different case.

Thanks
Rao
 
You could try this.

sed -e 's/[Oo][Ll][Dd]/New/g' file_name > new_file

This will replace old spelled with any combination of upper and lower case letters with New. If there is a better way, I'm sure someone will tell us.

Hope this helps.

CaKiwi
 
Hi rao!

If you wish to use gawk (GNU's version of awk; GNU, thanks! God bless you!), you can try this:

Code:
gawk -v IGNORECASE=1  '{ gsub(/old/,"new"); print }' file_name > new_file

When gawk's built-in variable IGNORECASE is true, gawk ignores case of all regular expressions. Function gsub is gawk's general substitution function.

Bye!

KP.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top