1.

Solve : Extract field after a particular parameter?

Answer»

I have a file where the contents of a parameter can come in any order:

part=NYRS1996,idm=CFTRCFG,type=message,msg=test
idm=CFTRCFG,type=message,msg=test,part=NYRS2002
part=NYRS2014,idm=CFTRCFG,type=message,msg=test
idm=CFTRCFG,part=NYRS3003,type=message,msg=test
part=NYRS3007,idm=CFTRCFG,type=message,msg=test
.....

I need to EXTRACT the filed after "part=", eg.,
NYRS1996
NYRS2002
NYRS2014
NYRS3003
NYRS3007


I was HOPING to avoid to avoid writting a cumbersome SCRIPT to do this. Is it possible to do this with a one/two liner unix COMMAND like sed or awk?
Code: [Select]awk -F"," '$1 ~ /^part/{sub(/part=/,"",$1);print $1}' file

from now on , your TASK is to start learning how to write shell scripts.



Discussion

No Comment Found