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 |
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.
|
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. |
It's certainly working for me.
Code:
$ testvar='1. FOOBAR |
All times are GMT -5. The time now is 07:24 AM. |