Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extract certain fields from file

Status
Not open for further replies.

nread

Technical User
Oct 31, 2001
58
GB
No idea how i would go about this, completly new to awk, but does anyone know how i would do the following :

I need to pull from a file all lines where the line has AddressStringDigits in it and CallTypeLevel1,2 &3... and enter into a new file

For example :

CDR 25,( AddressStringDigits 0x"0034607311112f"),(CallTypeLevel1 0x"02") -- 2,( CallTypeLevel2 0x"02") -- 2,
( CallTypeLevel3 0x"01") -- 1
CDR 26,( AddressStringDigits 0x"0034686830367f"),
( CallTypeLevel1 0x"02") -- 2,( CallTypeLevel2 0x"02") --2,
( CallTypeLevel3 0x"01") -- 1

Would be taken from :


-- CDR 25
( MobileOriginatedCall
( MoBasicCallInformation
( SimChargeableSubscriber
( Imsi 0x"214015001189242f")
)
( Destination
( TypeOfNumber 0x"00") -- 0
( NumberingPlan 0x"01") -- 1
( AddressStringDigits 0x"0034607311112f")
)
( CallEventStartTimeStamp
( LocalTimeStamp "20040224082330") -- 0x"3230303430323234303832333330"
( UtcTimeOffsetCode "/") -- 0x"2f", 47
)
( TotalCallEventDuration "6") -- 0x"36", 54
)
( LocationInformation
( NetworkLocation
( RecEntityCode 0x"07") -- 7
( LocationArea 0x"0145") -- 325
)
)
( BasicServiceUsedList
( BasicServiceUsed
( BasicService
( TeleServiceCode "11") -- 0x"3131", 12593
)
( ChargeInformationList
( ChargeInformation
( ChargedItem "D") -- 0x"44", 68
( ExchangeRateCode 0x"01") -- 1
( CallTypeGroup
( CallTypeLevel1 0x"02") -- 2
( CallTypeLevel2 0x"02") -- 2
( CallTypeLevel3 0x"01") -- 1
( CalledCountryCode "34") -- 0x"3334", 13108
)
( ChargeDetailList
( ChargeDetail
( ChargeType "00") -- 0x"3030", 12336
( Charge 0x"02a5") -- 677
( ChargeableUnits "6") -- 0x"36", 54
( DayCategory "I") -- 0x"49", 73
( TimeBand "I") -- 0x"49", 73
)
)
)
)
( DataVolumeReference 0x"00") -- 0
)
)
( CamelServiceUsed
( AddressStringDigits 0x"1134607009902f")
( CamelServiceLevel 0x"00") -- 0
( CamelServiceKey 0x"0d1d") -- 3357
( CamelCallReference
( AddressStringDigits 0x"447953706101")
( CamelCallReferenceNumber "1621819392") -- 0x"31363231383139333932"
)
)
)
-- CDR 26
( MobileOriginatedCall
( MoBasicCallInformation
( SimChargeableSubscriber
( Imsi 0x"214012001453079f")
)
( Destination
( TypeOfNumber 0x"01") -- 1
( NumberingPlan 0x"01") -- 1
( AddressStringDigits 0x"0034686830367f")
)
( CallEventStartTimeStamp
( LocalTimeStamp "20040224082207") -- 0x"3230303430323234303832323037"
( UtcTimeOffsetCode "/") -- 0x"2f", 47
)
( TotalCallEventDuration 0x"09") -- 9
)
( LocationInformation
( NetworkLocation
( RecEntityCode 0x"0d") -- 13
( LocationArea 0x"01b6") -- 438
)
)
( BasicServiceUsedList
( BasicServiceUsed
( BasicService
( TeleServiceCode "11") -- 0x"3131", 12593
)
( ChargeInformationList
( ChargeInformation
( ChargedItem "D") -- 0x"44", 68
( ExchangeRateCode 0x"01") -- 1
( CallTypeGroup
( CallTypeLevel1 0x"02") -- 2
( CallTypeLevel2 0x"02") -- 2
( CallTypeLevel3 0x"01") -- 1
( CalledCountryCode "34") -- 0x"3334", 13108
)
( ChargeDetailList
( ChargeDetail
( ChargeType "00") -- 0x"3030", 12336
( Charge 0x"02a5") -- 677
( ChargeableUnits 0x"09") -- 9
( DayCategory "I") -- 0x"49", 73
( TimeBand "I") -- 0x"49", 73
)
)
)
)
( DataVolumeReference 0x"00") -- 0
)
)
( CamelServiceUsed
( AddressStringDigits 0x"1134607009901f")
( CamelServiceLevel 0x"00") -- 0
( CamelServiceKey 0x"0d1c") -- 3356
( CamelCallReference
( AddressStringDigits 0x"447953710103")
( CamelCallReferenceNumber "1809907712") -- 0x"31383039393037373132"
)
)
)

I hope someone can make some sense of this...!!

Many thanks to whoever can help.

Nick
 
Something like this ?
awk '
$1=="--"{
if(length(buf))print buf
buf=$0
}
/AddressStringDigits/{buf=buf","$0}
/CallTypeLevel/{buf=buf","$0}
END{if(length(buf))print buf}
' /path/to/input >output

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
That certainly gets me the information, however, how would i get it to output only the values i.e. :

-- CDR971,07958225180f,1

Thanks for your help...!

-- CDR 971, ( AddressStringDigits 0x"07958225180f"), ( CallTypeLevel1 0x"01") -- 1,
 
Worked it out, thanks for your help.
 
Glad you have solved your issue yourself.
Thanks for sharing, can you please tell the members how you did it ?

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
$2=="CDR"{
if(length(buf))print buf
buf=$0
}
/AddressStringDigits/{buf=buf","substr($3,4,(length($3)-5))}
/Imsi/{buf=buf","substr($3,4,length($3)-6)}
/TypeOfNumber/{buf=buf","substr($3,4,length($3)-5)}
/NumberingPlan/{buf=buf","substr($3,4,length($3)-5)}
/LocalTimeStamp/{buf=buf","substr($3,2,length($3)-3)}
/TeleServiceCode/{buf=buf","substr($3,2,length($3)-3)}
/CallTypeLevel1/{buf=buf","substr($3,4,2)}
/CallTypeLevel2/{buf=buf","substr($3,4,2)}
/CallTypeLevel3/{buf=buf","substr($3,4,2)}
END{if(length(buf))print buf}


Thanks again...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top