New answers tagged


Besides that awk(same as and another text processors) is not a right xml-parsing tool: awk ' lines{ lines=lines "\n" $0 } /<\/record/{ if(lines ~ /keyword>SEARCH</) print lines lines="" } /<record/{ lines=$0 } ' <input.txt >output.txt Same as sed sed -n ...


If I have understood correctly, this might be a solution in awk!: /^<record/ { x1=""; while (match($0, "record>$")==0) { x1=x1 $0"\n"; getline; } x1=x1 $0; if (x1 ~ />SEARCH</) { print x1 > "output.txt"; } } This will extract the blocks, record> to \record>, containing the key "SEARCH" ...


I'm going to assume that what you've posted is a sample, because it isn't valid XML. If this assumption isn't valid, my answer doesn't hold... but if that is the case, you really need to hit the person who gave you the XML with a rolled up copy of the XML spec, and demand they 'fix it'. But really - awk and regular expressions are not the right tool for the ...


The enscript command seems to fit the bill. However, defining a new language seems to be a bit more complicated than in GtkSourceView.

Top 50 recent answers are included