Hi Everyone , have a great day
i have a file which has almost 20,000 blocks each starting with this particular line " rTCCreditControlRecord " , how can i bring out the 7172 block out of that file
Thanks in Anticipation
Hi Everyone , have a great day
i have a file which has almost 20,000 blocks each starting with this particular line " rTCCreditControlRecord " , how can i bring out the 7172 block out of that file
Thanks in Anticipation
Try both the following commands.
Not working , meanwhile i have tried something like this
while IFS= read -r EachLine
do
'echo $EachLine
if $EachLine = 'rTCCreditControlRecord'; then
count = count + 1
fi
if count = 7172; then
echo $EachLine
fi
done < CCN02
where CCN02 is input file but its not working either
if count = 7172; then
>>>that is a string comparison
if count -eq 7172; then
>>>that is a numeric comparison
I think you would want the numeric comparison.
-r: is not an identifier
#!/bin/sh
while IFS= read -r EachLine
do
#echo $EachLine
if $EachLine = 'rTCCreditControlRecord'; then
count = count + 1
fi
if count -eq 7172; then
echo $EachLine
fi
done < CCN02
Not Working
Add a display to echo to the screen what is happening. Could be count problem, $EachLine problem, file problem, etc...
By the way, wouldn't $EachLine be equal to the full line? rTCCreditControlRecord abcdefg 12345?
#!/bin/sh
while IFS= read -r EachLine
do
#echo $EachLine
if $EachLine = 'rTCCreditControlRecord'; then
count = count + 1
fi
echo $count $EachLine #for debug purposes
if count -eq 7172; then
echo $EachLine
fi
done < CCN02
[ ~/tmp/tccredit ] > cat CCN02
rTCCreditControlRecord abc 001
rTCCreditControlRecord abc 002
rTCCreditControlRecord abc 003
rTCCreditControlRecord abc 004
rTCCreditControlRecord abc 005
rTCCreditControlRecord abc 006
rTCCreditControlRecord abc 007
rTCCreditControlRecord abc 008
[ ~/tmp/tccredit ] > cat cntpr
#!/bin/bash
count=0
while read EachLine
do
prefix=$(echo $EachLine | cut -c1-22)
if [ "$prefix" = "rTCCreditControlRecord" ]
then
count=$(($count + 1))
fi
echo "debug=" $count $EachLine #for debug purposes
if [ $count -eq 5 ]
then
echo $EachLine
fi
done < CCN02
provides as output===>
[ ~/tmp/tccredit ] > cntpr
debug= 1 rTCCreditControlRecord abc 001
debug= 2 rTCCreditControlRecord abc 002
debug= 3 rTCCreditControlRecord abc 003
debug= 4 rTCCreditControlRecord abc 004
debug= 5 rTCCreditControlRecord abc 005
rTCCreditControlRecord abc 005
debug= 6 rTCCreditControlRecord abc 006
debug= 7 rTCCreditControlRecord abc 007
debug= 8 rTCCreditControlRecord abc 008
Note that the 5th record is what I was looking for in the process. Comment out my #debug purposes line to only get the 5th record.
I have something else. But I'm not sure of performance.
The following gives the 10th line of record containing "rTCCreditControlRecord" in the file