Use a different awk, works for me using text # awk --version awk version 20070501 (FreeBSD)
Fix your second xml file or find the workaround by yourself, my solution works for original data sample. text # cat file <?xml version="1.0" ?> <AUDITRECORDS> <CARF> <HED> <VN1>20090616010622</VN1> <VN2>0</VN2> <VN3>1090</VN3> <VN4>CONFIG_DATA</VN4> <VN5>20090616010622</VN5> <VN6>0</VN6> <VN7>1090</VN7> </HED> </CARF> <CARF> <HED> <VN1>20090616010651</VN1> <VN2>0</VN2> <VN3>1130</VN3> <VN4>11LOWE</VN4> <VN5>20090616010651</VN5> <VN6>0</VN6> <VN7>1130</VN7> </HED> </CARF> </AUDITRECORDS> # awk -F'[<|>]' '{ORS=($2 ~ "xml\|AUDITRECORDS\|\/CARF")?RS:OFS}1' OFS="" file <?xml version="1.0" ?> <AUDITRECORDS> <CARF><HED><VN1>20090616010622</VN1><VN2>0</VN2><VN3>1090</VN3><VN4>CONFIG_DATA</VN4><VN5>20090616010622</VN5><VN6>0</VN6><VN7>1090</VN7></HED></CARF> <CARF><HED><VN1>20090616010651</VN1><VN2>0</VN2><VN3>1130</VN3><VN4>11LOWE</VN4><VN5>20090616010651</VN5><VN6>0</VN6><VN7>1130</VN7></HED></CARF> </AUDITRECORDS>
---------- Post updated at 03:21 PM ---------- Previous update was at 01:10 PM ----------
When I try to reply to your second post i seen the original file format .... PLEASE read the Forum Rules and Guidelines and use [code] tags when you post data sample or code.
To keep the forums high quality for all users, please take the time to format your posts correctly.
First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags
```text
and
```
by hand.)
Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.
Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.
Here we change the OtherRecordSeparator, if the condition is true set the ORS to RecordSeparator(the default is new line), else set the ORS to OFS(Other filed separator) declared at the end.
1 is true and will print each record after processing.