Need help in scanning text files and find all the words between two patterns. Like say if we have a .sql file, Need to scan and find all words between from\' and \'where\'.
To return just a string within two given strings, along the lines of awk (without getting crazy) I just run this very flat script, verbosity in tow:
.\gnucoreutils\bin\awk "{startstring = \"RETURN STUFF AFTER ME \"; endstring = \"RETURN STUFF BEFORE ME\"; endofstartstring = index($0,startstring)+length(startstring); print substr($0,endofstartstring,index($0,endstring)-endofstartstring)}" /dev/stdin
Note that I am using cmd.exe (the command interpreter with Windows) and the gnuwin32 awk, so mind the "double-quotes" and ^\escape characters^\:
GNU Awk 3.1.6
Copyright (C) 1989, 1991-2007 Free Software Foundation.
Please point out flaws.
example:
echo "hello. RETURN STUFF AFTER ME i get returned RETURN STUFF BEFORE ME my face is melting" | .\gnucoreutils\bin\awk "{startstring = \"RETURN STUFF AFTER ME \"; endstring = \" RETURN STUFF BEFORE ME\"; endofstartstring = index($0,startstring)+length(startstring); print substr($0,endofstartstring,index($0,endstring)-endofstartstring)}" /dev/stdin
i get returned