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!

Hi, I have a set of files and i ne

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
 
If the regexp is not caste sensitive-i.e: if the regexp does not depend on mixed caste letters, why don't you just do a toupper($0) or tolower($0) before attempting the matches?

awk ' {
tolower($0)
if ($0 ~ /regexp/) {
matched = $0
gsub(/regexp/,newexp,matched)
}
print matched
}' filename

i didn't test this but the idea is a beginning at least.
 
rao12,

You can also try this:

Code:
gawk 'BEGIN { 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