Awk command for multi-line regex

Hello,

Assume an input file like this:

[name="n1"]
[name="n2"]

[TYPE description="description one"]

[name="n3"]
[TYPE description="description two"]

I need to assocate the description field of a [TYPE ] line with the name of the [name=] field which immediately precedes it in the file.  In the above example, for instance, the name "n2" would be associated with "description one" and "n3" would be associated with "description two".  There would be nothing associated with name "n1".  There may be zero or more blank lines between the [name] line and the [TYPE] line.

The output (to stdout) would look like the following:
n1 "description one"
n2 "description two"

Is this possible with Awk?

Thanks!


pennypiperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
> I need to assocate the description field of a [TYPE ] line with the name of the [name=] field which immediately precedes it in the file.  In the above example, for instance, the name "n2" would be associated with "description one" and "n3" would be associated with "description two".There would be nothing associated with name "n1".

This seems to contradict
> The output (to stdout) would look like the following:
n1 "description one"
n2 "description two"

Which is correct?  Or am I misinterpreting something?
0
pennypiperAuthor Commented:
Oops, typo.  You're right it should be:

n2 "description one"
n3 "description two"

Sorry about that.
0
ozoCommented:
awk -F'"'  '/\[name=/{n=$2};/\[TYPE/{print n " \"" $2 "\""}' inputfile
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pennypiperAuthor Commented:
That's what I was looking for.  Thanks ozo!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.