Hey guys this should be simple, I’m just not seeing it, I would like to create a regex (workable under PERL, Awk, SED / *nix) that will operate after it find a leading Cash ($), the very next Equal (=) and work on what is between either the first instance of double or single quotes to the last instance of double or single quotes.
Let me set up a few examples.
$this = 'operate on some text in here'; # operates between single quotes
$this = "operate on some text in here"; # operates between double quotes
$this = 'operate "on some text" in here'; # operates between single quotes
$this = 'operate \'on some text\' in here'; # operates between outer single quotes
I tried some really bad regex. but just couldn’t get it to match right.
Here’s what I’m inserting it into, in case anyones interested
printf '$request1 = "select * from whatever where this = that and active = 1 order by something asc";\n' |
grep '{regex}' * |
perl -pe 's/select/SELECT/g ; s/from/\n FROM/g ; s/where/\n WHERE/g ; s/and/\n AND/g ; s/order by/\n ORDER BY/g ; s/asc/ASC/g ; s/desc/DESC/g ;' | ## enter through file with all clauses
awk '{gsub(/\r/,"");printf "%s\n%d",$0,length($0)}' ## take first line convert to whitespace, use on following lines
Thanks guys!
Script:
will give you: