Reputation: 3483
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
Upvotes: 1
Views: 127
Reputation: 360535
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 ...
Upvotes: 1
Reputation: 342869
you can try using grep first, (and i assume you are on Solaris.)
grep -i "update.*set" "$TEST" | egrep -vi "updatesql|updated" | nawk .....
Upvotes: 0