How to match two key words in a paragraph

How to match two key words in a paragraph

am 20.04.2008 02:39:41 von webinfinite

Hi,

I have a document in which I like to look for key words: wordA and
wordB. I need to first find where wordA is located in the paragraph
and from this position, I need to find wordB's value. For example,

Hello, World
This {

}

Re: How to match two key words in a paragraph

am 20.04.2008 02:45:02 von webinfinite

Sorry, I didn't finish in the above thread. Let me reinstate:

I have a document in which I like to look for key words: wordA and
wordB. I need to first find where wordA is located in the paragraph
and from this position, I need to find wordB's value. For example,

Hello, World
This {
value = "ABC"
}
That {
value = "DEF"
}

I need to first find out "That". At this point, I don't need anything
above "That". Then I need to find out in the paragraph under where
"That" is located if the value equals "DEF".

Could anybody tell me how I can find out two words in paragraph? nawk
can be used for keywords in a single line but here I need to do a
similar task in a paragraph. Any suggestion?

Re: How to match two key words in a paragraph

am 20.04.2008 03:05:51 von Ed Morton

On 4/19/2008 7:45 PM, webinfinite@gmail.com wrote:
> Sorry, I didn't finish in the above thread. Let me reinstate:
>
> I have a document in which I like to look for key words: wordA and
> wordB. I need to first find where wordA is located in the paragraph
> and from this position, I need to find wordB's value. For example,
>
> Hello, World
> This {
> value = "ABC"
> }
> That {
> value = "DEF"
> }
>
> I need to first find out "That". At this point, I don't need anything
> above "That". Then I need to find out in the paragraph under where
> "That" is located if the value equals "DEF".
>
> Could anybody tell me how I can find out two words in paragraph? nawk
> can be used for keywords in a single line but here I need to do a
> similar task in a paragraph. Any suggestion?

It's easily done in awk. Exactly how depends on more details about your input
file, but one way given the file you show above would be:

awk -v RS="}" '$1=="That" && $5=="\"DEF\""{ print "found" }' file

If that doesn't work on your real input file, provide a more truly
representative sample input, expected output from that input, and description of
how to find the fields you're interested in.

Regards,

Ed.