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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extracting data from files...

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I know pretty much nothing about Perl so i'd be grateful if someone could explain to me how i would a) search a file and look for all records within that file with a ( "teleservice code" = "22" )
where the ("totalcalleventduration") not equal to 0
and b) print the record name e.g. CDR2

Check out the example of a record below...

Thanks in advance for any help at all......

-- CDR 2
( MoBasicCallInformation
( SimChargeableSubscriber
( Imsi 0x"234305683001762f")
)
( Destination
( TypeOfNumber 0x"01") -- 1
( NumberingPlan 0x"01") -- 1
( AddressStringDigits 0x"447958879879")
( ModificationIndicator 0x"01") -- 1
)
( CallEventStartTimeStamp
( LocalTimeStamp "20020418224849") -- 0x"323030323034313832323438343
9"
( UtcTimeOffsetCode "A") -- 0x"41", 65
)
( TotalCallEventDuration 0x"00") -- 0
)
( LocationInformation
( NetworkLocation
( RecEntityCode 0x"06") -- 6
( LocationArea 0x"0a96") -- 2710
( CellId 0x"07") -- 7
)
)
( EquipmentInformation
( MobileStationClassMark 0x"04") -- 4
( Imei 0x"3501879055650800")
)
( BasicServiceUsedList
( BasicServiceUsed
( BasicService
( TeleServiceCode "22") -- 0x"3232", 12850
)
( ChargeInformationList
( ChargeInformation
( ChargedItem "E") -- 0x"45", 69
( ExchangeRateCode "A") -- 0x"41", 65
( CallTypeGroup
( CallTypeLevel1 0x"02") -- 2
( CallTypeLevel2 0x"00") -- 0
( CallTypeLevel3 0x"00") -- 0
( CalledCountryCode "44") -- 0x"3434", 13364
)
( ChargeDetailList
( ChargeDetail
( ChargeType "00") -- 0x"3030", 12336
( Charge "W") -- 0x"57", 87
( DayCategory "I") -- 0x"49", 73
( TimeBand "I") -- 0x"49", 73
)
)
)
)
)
)
 
my $totalFlag = 0;
my $codeFlag = 0;
my $recordName;

open (FILE, &quot;<log.file&quot;);
while (<FILE>){
if (/^--(.+)/){ #if &quot;--&quot; marks begining of record
if (($tatalFlag ne 0) and ($codeFlag eq 22)){
print $recordName, &quot;\n&quot;;
}
$recordName = $1;
$codeFlag = 0;
$totalFlag = 0;
}
$codeFlag = 22 if (/TeleServiceCode &quot;22&quot;/);
$totalFlag = 1 if (/TotalCallEventDuration (?!0x&quot;00&quot;)/);
}
if (($tatalFlag ne 0) and ($codeFlag eq 22)){
print $recordName, &quot;\n&quot;;
}

close FILE;

#this code should extracting and print to the console record names you need from &quot;log.file&quot;.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top