Home / Software / BSD, Linux, and Unix / Extract field after a particular parameter
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] - (Bottom) Print
Author Topic: Extract field after a particular parameter  (Read 770 times)
et_phonehome_2
Topic Starter
Rookie



Thanked: 1
Posts: 40


« on: November 13, 2009, 03:13:54 PM »

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?
IP logged
gh0std0g74
Apprentice



Thanked: 37
Posts: 590


« Reply #1 on: November 13, 2009, 08:15:12 PM »

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.
IP logged

Pages: [1] - (Top) Print 
Home / Software / BSD, Linux, and Unix / Extract field after a particular parameter « previous next »
 


Login with username, password and session length

Old Forum Search | Forum Rules
Copyright © 2010 Computer Hope ® All rights reserved.
Powered by SMF 2.0 RC3 | SMF © 2006–2010, Simple Machines LLC
Page created in 0.075 seconds with 20 queries.