Search code examples
regexlinuxshellawknawk

Linux: Extract and transform attributes from line


if got a file, with lines in the following format:

SOME_ATTRIBUTE_1 XYZ; IMPORTANT_ATTRIBUTE_1 1234; SOME_ATTRIBUTE_2 XYZ; IMPORTANT_ATTRIBUTE_2 AB;

Now I want to transform this into the following form, that the two important attribute values produce a new attribute:

JOIN_IMPORTANT_ATTRIBUTE AB1234; SOME_ATTRIBUTE_1 XYZ; IMPORTANT_ATTRIBUTE_1 1234; SOME_ATTRIBUTE_2 XYZ; IMPORTANT_ATTRIBUTE_2 AB;

Can this be done with some one-liner with awk or similar? I've got no idea how to tacle this, without grabbing into the java trickbox.


Solution

  • awk -F'[; ]+' '{print "JOIN_IMPORTANT_ATTRIBUTE", $8 $4 "; " $0}' file