I am new to shell scripting, i need your help to tackle a problem.
I have a single file, sample is below:
Now the same file contains the following records
Now I want to get all the msisdns values (after = sign) from two different statements
INFO line [ msisdn = 130174, bonus = 16147, total usage = 161471 ]
INFO AIR credit operation success [ msisdn = 130174]
compare them, in case they are equal i want to output them like displayed below
The values that are not found in both sets of data can be output in an error file
Guys i need help to create this logix in UNIX/Solaris machine. So far i am unable to use the scripting knowledge that i have to perform this function.
So the essence of the problem is that when a USE for the credit (the "success" message) for a particular msisdn, you want to record all the "line" information for that msisdn. But the USE record comes AFTER the recording record. Is that the core of it?
I have a few questions...
1) Is this all being recorded moment by moment in one file like a log, or are the "USE" records in a separate file?
2) It makes sense that if there is a USE record where there has been no line record it would be an error.
3) Can you get two "line records" with the same msisdn without a USE record in between? If yes, you must account for this. How about the reverse? Two or mor uses for each recording? Either that is an error too, or you add up the credits or something, etc.
4) What happens if a line record never gets used? That is, how long do you hold (store) un-used "line records" before they become errors (if they ever do)?
I would start by storing the "line records" in a hash (perl). Basically you read along this file and every time you encounter a "line record" you store it using the msisdn as the index of the hash. As you come across a USE record (I'm assuming one log file here that is growing was you are reading it), you look for it's msisdn already in the hash (exists() in perl). If found, you have the line data as the value of the hash, and you can DELETE that value from the hash since it is accounted for, etc. That would be one way to approach it. If you don't have hashes, you will have to use an array, search it, etc. So long as the number of un-used line records stays low, performance shouldn't degrade.
$> ./check_msisdn a
Going to scan the file : a
msisdn mismatch found
cur_msisdni : 113220
prev_msisdn : 13220
and the contents of file a were the same that you have provided except for a change in the line
------------------------------------------------------------
2008:07:08 07:03:20.656 (tid 4) INFO Bonus required [ msisdn = 13220, bonus = 18960, total usage = 189606 ]
2008:07:08 07:03:20.687 (tid 4) INFO AIR credit operation success [ msisdn = 113220]
---------------------------------------------------------------
1) Is this all being recorded moment by moment in one file like a log, or are the "USE" records in a separate file?
2) It makes sense that if there is a USE record where there has been no line record it would be an error.
3) Can you get two "line records" with the same msisdn without a USE record in between? If yes, you must account for this. How about the reverse? Two or mor uses for each recording? Either that is an error too, or you add up the credits or something, etc.
4) What happens if a line record never gets used? That is, how long do you hold (store) un-used "line records" before they become errors (if they ever do)?
Hi all,
We have a requirement like we need to create a program which will change a particular string in the file. For example
+=KA1238767 1121 3344645 686943 22356
01 567893 12435 12121 983627 121 1092 091217
02 may be for engine failure
In the above file we need to change the bold string... (2 Replies)
Hi,
Can anyone please help me on building the logic for writing a shell script which can delete blank lines from a file and count the number of duplicate lines in a file.
Thanks,
Indra (2 Replies)