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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Case insensitive sed

Status
Not open for further replies.

IMAUser

Technical User
May 28, 2003
121
CH
Hi ,

We have a standard Solaris installation so no "i" option for case insensitive sed.

I have a lot of oracle views in which I need to replace the table names with different tablenames. There is one script per view.

So the set of oracle scripts is like V_123.sql , V_ABC.sql , V_DEF.sql etc.

Now, I have created a file(replace_tab_names.txt) with what I need to replace, and the contents are as below
{
s/TAB_NAME_A/TAB_NAME_NEW_A/ig
s/TAB_NAME_B/TAB_NAME_NEW_B/ig
s/TAB_NAME_C/TAB_NAME_NEW_C/ig
}

Then I have shell script (sed_replace.sh) which looks like

for filename in `ls -1 V_*.sql `
do
sed -f replace_tab_names.txt $filename > $filename.A2
done

Ofcourse it says
sed: command garbled:
and that is because of the "i" for case insensitive option.

Any ideas how else could I do this..

Many Thanks.

 
Replace this:
s/TAB_NAME_A/TAB_NAME_NEW_A/ig
with this:
s/[Tt][Aa][Bb]_[Nn][Aa][Mm][Ee]_[Aa]/TAB_NAME_NEW_A/g

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi

[tt][blue][small][ignore][off-topic][/ignore][/small][/blue][/tt]
Or you could transform for [tt]sed[/tt] code into [tt]perl[/tt] code :
Code:
[b]s[/b][fuchsia]/TAB_NAME_A/TAB_NAME_NEW_A/[/fuchsia][b]ig[/b][highlight][teal];[/teal][/highlight]
[b]s[/b][fuchsia]/TAB_NAME_B/TAB_NAME_NEW_B/[/fuchsia][b]ig[/b][highlight][teal];[/teal][/highlight]
[b]s[/b][fuchsia]/TAB_NAME_C/TAB_NAME_NEW_C/[/fuchsia][b]ig[/b][highlight][teal];[/teal][/highlight]
Then use it like accordingly :
Code:
[b]for[/b] filename [b]in[/b] `ls -[purple]1[/purple] V_[teal]*.[/teal]sql`
[b]do[/b]
  [highlight]perl[/highlight] [highlight]-p[/highlight] replace_tab_names[teal].[/teal]txt  [navy]$filename[/navy] [teal]>[/teal] [navy]$filename[/navy][teal].[/teal]A2
[b]done[/b]
[tt][blue][small][ignore][/off-topic][/ignore][/small][/blue][/tt]

Feherke.
 
Thanks PHV and feherke.

PHV: Sorry, maybe the example was not clear enough. The no of tables I have is about 70, and to type in every char in lower and upper for ever table would be a pain.

feherke: Yes that does the trick. But for a certain entry in replace_tab_names.txt the substitution happens twice. I guess there is something specfic to that tablename , so I need to check.

But many thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top