1

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 implement this using grep, awk, or sed?

1
  • What are you supposed to be doing when you find the tag? I'd do it with a quick Perl script myself, but then I'm very much the Perl hacker. Commented Feb 24, 2010 at 21:54

1 Answer 1

3
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"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.