How can I search with start and end criteria?

Hello

I'm using cygwin and wouldlike extract information from an xml file according specific values, but don't know how.

Let's say in a file content looks like this:

 
<tab>
    SURNAME=Mustermann
    NAME=Max
    CUSTOMER SINCE= 18.01.2000
    ADDRESS=Birmingham
    DESCRIPTION=likes red
    etc
</tab>
 
<tab>
    SURNAME=Doe
    NAME=John
    CUSTOMER SINCE= 18.01.2002
    ADDRESS=Berlin
    PARAMETERX= anything
    DESCRIPTION=something
    etc
</tab>

the block starts and ends for each customer with tab /tab but the parameter in between could be different.

e.g. I want the output of all customers which has DESCRIPITON=likes red and ADDRESS starts with B

how can I define the search for both creteria is just between the start and end parameter tab?

I hope you understand what I mean :smiley:

Thanks in advance

This can easy be solved by using Record Selector RS

Search for DESCRIPTION=likes red and ADDRESS=B

awk '/DESCRIPTION= *likes red/ && /ADDRESS= *B/' RS="</tab>" file

You can also add an Output Record Selector ORS if you want the closing </tab> in the output:

awk '/DESCRIPTION= *likes red/ && /ADDRESS= *B/' RS="</tab>" ORS="</tab>\n" file
1 Like