All lines between <input> and </input> is one 'order' and this 'order' is repeated several times, but the first and last line for all the 'orders' are same i.e. <input> and </input>.
I need the entire 'order' containing a string (value=""), i.e. all lines between <input> and </input> containing value="".
Now in the xml, I have many occurrences of value="", I need all 'orders' containing value="" in a separate file.
Restrictions:
1) one 'order' may contain more than one value="", for that I need the order only once in the output file.
Normally awk has record separator as \n and field separator as space. But in the code we are overriding it to record seperator as "" and field seperator as </input>
so each record has the value of <input>..........<blah>
in that record, we are checking $0~/\"\"/ (any record has two double quotes... "" )
if yes, then print it
---------- Post updated at 08:27 PM ---------- Previous update was at 08:27 PM ----------
Thanks itkamaraj and dude2cool for the help... @itkamaraj, thanks for the awk tutorial link. its too good....
I want to do one thing with this awk. It would be great if you can help me....
Previous code:
nawk -v "mydate=`date`" 'BEGIN{RS=""; FS="\</inputProvision\>"} {print mydate ; for(i=1;i<=NF;i++){ if ($i~/\"\"/) print $i"</inputProvision>"}}' test
$i prints everything before </inputProvision> where value="".......... This is what I want.
I also want to print a a tag along with it which is a part of $i.
For that I am doing:
nawk -v "mydate=`date`" "var2=`grep XYZ $i`" 'BEGIN{RS=""; FS="\</inputProvision\>"} {for(i=1;i<=NF;i++) { if ($i~/value=\"\"/) print var2 mydate $i "</inputProvision>"}}' test
basically in $i, there is a field called XYZ in the format:
<ATTR name="XYZ" value="123456789"/>
I need it's value to be printed along with $i...
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.