awk nested looping?

I am trying to parse a text file and send its output to another file but I am having trouble conceptualizing how I am supposed to do this in awk.

The text file has a organization like so:

Name
Date
Status
Location (city, state, zip fields)

Where each of these is on a separate line in the file and there are hundreds of such records. Note that Name does not have a standard set of fields (columns) but the other lines do.

What I want to do is search for a string in the Name line such as "Jones" and if and only if there is a match print the city for that record else go to the next record. The records, however, are not defined in any machine readable way like with some kind of delimiter.

So the program flow as I imagine it should look something like this:

Step 1. Find a line that begins with "N" (indicating a line with Name)

Step 2. Check to see if that line has the word "Jones" in it.

Step 3. If it does not, skip down to the next line that begins with "N" and repeat Step 2. Otherwise Step 4.

Step 4. If the line does have word "Jones " in it skip down two lines from the line that began with "N" to the line that begins with "L"

Step 5. Locate the City (which is in the 1st column) and write that text string to a file.

Step 6. Goto step 1.

Step 7. Repeat until end of file is reached.

So the expected output would be something along the lines of :

New York
LA
Dallas

Because all these are places with a customer called "Jones" but a city which had no customer with the name of Jones would not be on this list.

Where I am getting confused is on Step 3 and 4. Awk doesn't have a "where" operator so how do I tell awk to skip down two lines if and only if there was a match on "Jones" otherwise ignore the Location line and continue until it does have a match?

---------- Post updated at 08:48 PM ---------- Previous update was at 08:39 PM ----------

I guess another way to look at this problem would be to say:

How do I tell awk to print the City column in a line that begins with Location if and only if the immediately proceeding occurance of a line beginning with Name contained the word "Jones".

Is this a homework assignment? Homework and coursework questions can only be posted in the Homework & Coursework forum under special homework rules.

If this is not homework, please explain the company you work for and the nature of the problem you are working on. And:

  1. tell us what operating system you're using
  2. what shell you're using, and
  3. show us what you have tried to solve this problem on your own.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.