How to cut word and value from cut command field value

cutgreptext processing

This is the line format of the my file:

29.101.26.176 [11/Oct/2017:10:21:41 /pmk/clk?aff_id=5863&off_id=85635&trans_id=easoli4ddq8sssdf&prm2=23398_27530&device_id=864792012331091090 "Mozilla/5.0 Mobile

I need to cut aff_id=5863 and off_id=85635 and trans_id=easoli4ddq8sssdf.

I can only cut the specific field from cut command not the word inside the field. How can I separate the given word?

Best Answer

Short grep approach:

grep -Eo '([ao]ff|trans)_id=[^&]+' file

The output:

aff_id=5863
off_id=85635
trans_id=easoli4ddq8sssdf

----------

Or awk solution for fixed item order:

awk -F'[?&]' '{ printf "%s %s %s\n",$2,$3,$4 }' file

The output:

aff_id=5863 off_id=85635 trans_id=easoli4ddq8sssdf
Related Question