How to replace a string (case insensitive)?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to replace a string (case insensitive)?
# 1  
Old 10-28-2010
How to replace a string (case insensitive)?

Hi,

Please help me in following prob.

I have a input file in which UPDATE statements will be present. I need to check the count of the rows impacted by each statement. I am using below code to do so:

$dml --> File having UPDATE SQLs like
Update <table_name> Set <field>=<value> where <field>=<value>

$temp1 --> Temporary file having only WHERE clause of the SQLs present in $dml

$ddl --> Having SELECT COUNT(*) statements using the WHERE clause present in $temp1
Code:

cnt=`cat $dml | grep -c "where"  | tr -s " "` 
sed 's/.*\(where .*$\)/\1/' $dml > $temp1 
sed "s/where/select count(*) from $SCH.$TBL where/" $temp1 > $ddl

ISSUE: If the SQL in the input file ($dml) have WHERE or Where instead of where then this code does not work.


So I need to make it case insensitive....
I can make "cnt=`cat $dml | grep -c "where" | tr -s " "` " case insensitive by adding -i in grep:
cnt=`cat $dml | grep -c -i "where" | tr -s " "` .


Please suggest me if this is wrong and I need to make the rest of the 2 commands case insensitive...


sed 's/.*\(where .*$\)/\1/' $dml > $temp1
sed "s/where/select count(*) from $SCH.$TBL where/" $temp1 > $ddl
# 2  
Old 10-28-2010
Code:
cnt=`cat $dml | grep -c "where"  | tr -s " "` 
sed 's/.*\([wW][hH][eE][rR][eE] .*$\)/\1/' $dml > $temp1 
sed "s/[wW][hH][eE][rR][eE]/select count(*) from $SCH.$TBL where/" $temp1 > $ddl

# 3  
Old 10-28-2010
thanks...
this is working...
# 4  
Old 10-28-2010
No temp file generated.

Code:
cnt=`cat $dml | grep -c "where"  | tr -s " "` 
awk -v s=$SCH -v t=TBL 'tolower($(NF-1))=="where" {$0="select count(*) from " t "." s " where " $NF}1'  $dml >  $ddl

---------- Post updated at 11:19 AM ---------- Previous update was at 09:00 AM ----------

if you have gawk and support IGNORECASE=1

Code:
awk -v s=$SCH -v t=TBL 'BEGIN{IGNORECASE=1}/where/{$0="select count(*) from " t "." s " where " $NF}1'  $dml

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Making SED case insensitive

Dears, In the below string, please let me know how to make the sed search case-incensitive. I have more such lines in my script instead of let me know any other easier option. sed -n '/dn: MSISDN=/,/^\s*$/p' full.ldif > temp ; sed -n... (4 Replies)
Discussion started by: Kamesh G
4 Replies

2. Shell Programming and Scripting

Case insensitive file name search and replace

I am trying to find case insensitive file names and then replace that particular file with other name. if then ls | grep -i "update" | xargs -I {} mv {} LineItems.csv echo "File moved from *update*" elif then ls | grep -i "priority" | xargs -I {} mv {} ... (1 Reply)
Discussion started by: ATWC
1 Replies

3. Shell Programming and Scripting

Making case insensitive in awk

here is a statement awk '/CREATE PROCEDURE/,/elimiter/' "$file1" > onlyproc1.sql which mean cut from create procedure to Delimiter or delimiter and paste it in onlyproc1.sql... my query is how to make this case insensitive.. that is i want the above code to work whther it is Delimiter or... (26 Replies)
Discussion started by: vivek d r
26 Replies

4. UNIX for Dummies Questions & Answers

more command case insensitive search ?

Hello, How do I set case insensitive search mode while the file is open with more command ? (I know -i option which could be used before opening) thanks Vilius (2 Replies)
Discussion started by: vilius
2 Replies

5. Shell Programming and Scripting

Case Insensitive search

Hey , i am trying to do a search for the certain books , and im trying to make it case insensitive. what i have come up with so far is this : Database.txt RETARDED MONKEY:RACHEAL ABRAHAML:30:30:20 GOLD:FATIN:23.20:12:3 STUPID:JERLYN:20:40:3 echo -n "Title: " read Title echo -n... (3 Replies)
Discussion started by: gregarion
3 Replies

6. Shell Programming and Scripting

case-insensitive search with AWK

Hi All, How we can perform case-insensitive search with AWK.:rolleyes: regards, Sam (11 Replies)
Discussion started by: sam25
11 Replies

7. Shell Programming and Scripting

case-insensitive if on substring

I'd like to print a line if a substring is matched in a case insensitive manner something like do a case insensitive search for ABCD as a substring: awk '{ if (substr($1,1,4) == "") print $1 }' infile > outfile I'm not certain how to make the syntax work??? Thanks (4 Replies)
Discussion started by: dcfargo
4 Replies

8. Shell Programming and Scripting

case insensitive

hi everyone, I need to do the following thing in a case insesitive mode sed 's/work/job/g' filename since work could appear in different form as Work WORK WorK wORK,.... I was wondering if i could do a case insensitive search of a word. thanks in advance, :) (4 Replies)
Discussion started by: ROOZ
4 Replies

9. Shell Programming and Scripting

awk case-insensitive

can I tell awk to be case insensitive for one operation without setting the ignorecase value ? thanks, Steffen (7 Replies)
Discussion started by: forever_49ers
7 Replies

10. UNIX for Dummies Questions & Answers

case insensitive locate

How can I do a case insensitive locate? (3 Replies)
Discussion started by: davis.ml
3 Replies
Login or Register to Ask a Question