Matching and printing line with awk

Hi there,

I'm trying to use awk to print out the entire line that contains a match to a certain regex and then append some text,plus the match to the end of the line.

So far I have:

awk -F: '{print "RG:Z:" $2}' file

Which prints out the match I want plus the additional text, but I'm stuck on how to also print out the entire line as well as that. I'm not an expert with awk unfortunately, I could do it in perl easily enough but I think awk may be faster, which is useful given the files I'm working with are 4-500GB.

awk -F: '/regex/{print $0" RG:Z:"$2}' file
1 Like

Simple as that eh! Work's great, thank you!

Anytime.