开发者

Shell Script, Search File for String

开发者 https://www.devze.com 2022-12-21 16:49 出处:网络
I\'m writing a shell script that opens a file and needs to find a tag like ##FIND_ME##.The string I\'m searching for is a constant (and there is only ever one instance of it.)

I'm writing a shell script that opens a file and needs to find a tag like ##FIND_ME##. The string I'm searching for is a constant (and there is only ever one instance of it.)

Once I locate that string, I need it to start a new search for a different string from that point forward.

My *nix skills are a little rusty, should try to impleme开发者_StackOverflownt this using grep, awk, or sed?


awk '/FINDME/{f=1}f&&/NEWSEARCH/{print}' file

shell

f=0
while read -r line
do
 case "$line" in
   *FINDME* ) f=1;;
 esac
 if [ "$f" -eq 1 ] ;then
    case "$line" in
      *NEWSEARCH*) echo "found next tag in: $line";;
    esac
 fi
done <"file"
0

精彩评论

暂无评论...
验证码 换一张
取 消