Karl Karl - 1 month ago 10x
Linux Question

Short way to apply gensub to all fields in awk

I have this awk command which reads single line xml with different fields. I had to use gensub on all fields one by one.

suppose this is my xml file


The output i want is


Also i want to use from command line and i would like one liner if possible.
Is there any way to make this command short

awk -v FS='><' -v RS="</?user>" '{
a=gensub(/.*>(.*)<.*/, "\\1", "g", $1);
b=gensub(/.*>(.*)<.*/, "\\1", "g", $2);
c=gensub(/.*>(.*)<.*/, "\\1", "g", $3);
print a"--"b"--"c}' abc.xml

$ awk -F'<[^>]+>' -v OFS='--' '{print $4, $6, $8}' file

If that's not what you want then edit your question to provide more truly representative sample input and expected output.