Sponsored Content
Top Forums Shell Programming and Scripting Help building the logic for a script Post 302212970 by snowline84 on Wednesday 9th of July 2008 12:06:17 AM
Old 07-09-2008
need few clarifications

Hi,
I need few clarifications in the requirements.
In the file, are we supposed to check only the lines that contains

"INFO Bonus required "

to the next line that contains

"INFO AIR credit operation success "???

If yes, we can go for a simpe script like


-----------------------------------------------------------------------

if [ $# -lt 1 ]
then
echo "Usage : " $0 "<file_name>"
exit 1
fi

echo "Going to scan the file : "$1

file_name=`echo $1`

prev_line=2

for cur_line in `cat $file_name | tr ' ' '+'`
do

echo $prev_line | grep "INFO+Bonus+required+" >test_file

if [[ -s test_file ]]
then
prev_msisdn=`echo $prev_line | tr ',' '+' | tr -s '+' | cut -d '+' -f 11`
cur_msisdn=`echo $cur_line | tr ']' '+' | tr -s '+' | cut -d '+' -f 13`

if [ "$prev_msisdn" -ne "$cur_msisdn" ]
then
echo "msisdn mismatch found"
echo "cur_msisdni : "$cur_msisdn
echo "prev_msisdn : "$prev_msisdn
fi
fi


prev_line=`echo $cur_line`

done
-----------------------------------------------------------------------




which works like

$> ./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]
---------------------------------------------------------------
 

2 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help required on building the logic

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)
Discussion started by: igandu
2 Replies

2. Shell Programming and Scripting

Need help in building Unix script

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)
Discussion started by: susant.igate
2 Replies
All times are GMT -4. The time now is 04:21 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy