tags:

views:

12

answers:

2

I am trying to get Update queries from a list of files using this script.I need to take lines containing "Update" alone and not "Updated" or "UpdateSQL"As we know all update queries contain set I am using that as well.But I need to remove cases like Updated and UpdatedSQL can anyone help?

nawk -v file="$TEST" 'BEGIN{RS=";"}
  /[Uu][Pp][Dd][Aa][Tt][Ee] .*[sS][eE][tT]/{ gsub(/.*UPDATE/,"UPDATE");gsub(/.*Update/,"Update");gsub(/.*update/,"update");gsub(/\n+/,"");print file,"#",$0;}  
  ' "$TEST"  >> $OUT
A: 

you can try using grep first, (and i assume you are on Solaris.)

grep -i "update.*set" "$TEST" | egrep -vi "updatesql|updated" | nawk .....
ghostdog74
+1  A: 

This seems more readable to me without all the [Uu] and it doesn't require grep:

{ line=tolower($0); if (line ~ /update .*set/ && line !~ /updated|updatesql/) { gsub ...
Dennis Williamson