LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 07-27-2009, 04:38 AM   #1
filip
LQ Newbie
 
Registered: Jul 2009
Posts: 2

Rep: Reputation: 0
SED - case insensitive pattern restriction


Hi,
I have a lot of Oracle DB package bodies in files and need to replace the names of internal called procedures/functions.
A small example:
suppose we want to change InsertCustomer to InsCust in a procedure like this:

PROCEDURE InsertCustomers () AS
BEGIN
SELECT InsertCustomer() FROM DUAL; -- this should be replaced
...
SELECT someOtherPackage.InsertCustomer() FROM DUAL -- this not
END InsertCustomers;

I need a restriction for sed, which excludes the lines 1,5 and 6 but in case insensitive mode (END can also be end or End, ...). There's an option /i in sed for the case insensitive mode, but that only applies for replacement and not for the restriction pattern.

I use following command, but that excludes only lines with PROCEDURE, FUNCTION, END in upper case and 'anything.InsertCustomer':

sed '/^\(PROCEDURE\|FUNCTION\|END\|.*\+\.InsertCustomer\)/ !s/InsertCustomer/InsCust/i'

I also need to have the ability to exclude lines like this:
anything.insertcustomer
anything.INSERTCUSTOMER
End
procedure
...

Thank you for any help.
Filip
 
Old 07-27-2009, 09:38 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948
According to this, gnu sed has an 'I' flag for case-insensitivity that can be used after regex expressions. I've tried a couple of simple tests and it seems to work both in the matching and in the replacement expressions.
 
Old 07-28-2009, 03:23 AM   #3
filip
LQ Newbie
 
Registered: Jul 2009
Posts: 2

Original Poster
Rep: Reputation: 0
Hi David,
thank you for your answer. You are absolutely right about the I flag, but as you said it works for matching and replacement, but not for the restriction regex.

Take a sed command like this:

sed '/restriction_regex/ s/match_regex/replace_regex/I'

The I flag will work on match_regex and replace_regex, but the restriction_regex will not be executed in case insensitive mode.
 
Old 07-28-2009, 08:08 AM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948
It's certainly working for me.
Code:
$ testvar='1. FOOBAR
2. foobar
3. FooBar
4. barbum
5. BARBUM'


$ echo "$testvar" |sed -n '/foo/I s/bar/bum/Ip'
1. FOObum
2. foobum
3. Foobum

$ echo "$testvar" |sed -n '/BUM/I s/bar/bum/Ip'
4. bumbum
5. bumBUM
 
  


Reply

Tags
case, sed


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Evaluate strings as case-insensitive gchilders Linux - Newbie 4 10-13-2008 04:27 PM
Case insensitive authentication with PAM BillyCrook Linux - General 11 07-02-2008 03:54 AM
Copying files from case-sensitive Linux to case-insensitive Windows via CIFS? SlowCoder Linux - General 4 05-07-2008 07:03 PM
Case-insensitive CVS? sundialsvcs Programming 2 06-25-2006 10:01 AM
case insensitive search command ColKurtz Linux - Newbie 4 01-20-2005 07:02 AM


All times are GMT -5. The time now is 08:30 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration