Grep Access Multiple lines, find all words between two patterns

后端 未结 5 1673
星月不相逢
星月不相逢 2020-12-20 14:59

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\'.

5条回答
  •  心在旅途
    2020-12-20 15:21

    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
    

提交回复
热议问题