I have a script that uses a loop within a loop, for some reason the script seems to hang on a particuliar record. The record is fine and hits the condition in Blue. If I kill the 1st loop process the script continues on with no problem.
Begin code>
<Some other code>
cat $fileloc2 | while read line
do
npanxx=`echo $line |cut -c1-6`
ocn=`echo $line | cut -c10-13`
brange=`echo $line |cut -c14-17`
erange=`echo $line |cut -c18-21`
revnpa=`echo $npanxx|sed '/\n/!G;s/\(.\)\(.*\n\)/&\2\1/;//D;s/.//'`
cat $ocnfile |cut -c1-4| while read input
do
if [ $ocn = $input ]
then
if [ $pnpanxx != $npanxx ] and [ $frange != T ]
then
pnpanxx=$npanxx
if [ $brange = 0000 ]
then
if [ $erange = 9999 ]
then
frange=T
sed 's/NPANXX/'$npanxx'/g;s/XXNAPN/'$revnpa'/g;s/Y/I/g' $hfile >> $tempfile
else
frange=F
erange=`expr $erange + 1`
sed '0001,'$erange'!d' $hfile > $temp
sed 's/NPANXX/'$npanxx'/g;s/XXNAPN/'$revnpa'/g;s/Y/I/g' $temp >> $tempfile
rm $temp
fi
else
frange=F
brange=`expr $brange + 1`
erange=`expr $erange + 1`
sed ''$brange','$erange'!d' $hfile > $temp
sed 's/NPANXX/'$npanxx'/g;s/XXNAPN/'$revnpa'/g;s/Y/I/g' $temp >> $tempfile
rm $temp
fi
fi
fi
done
done
you might want to check the size of $temp --- it's probably 0 bytes ... i'm guessing that you're killing the sed process in this loop when it hangs because $brange and $erange seem to be within single quotes and are unusable to sed ...
The $hfile is a hidden file that contains static values that I use a for global replace. I have to create anywhere from 1000 to 10000 block telephone numbers. the vales 0000 - 9999 never change. so I use the sed statement to pull the block out that I need brange = begin range erange = end range. Then I use a global replace on the static values. Lot faster than doing +1 especially if you have to create close to 21 mil records.
This simply strips out duplicates. The table I am parsing has ranges in it
312 314 0000-9999
sometimes the next record would have the same value in it but a smaller range which has already been built.
312 314 0000-9999
312 314 1000-1999
pnpanxx = previous npanxx in file, npanxx = current one I am looking at
I set the frange value to T or F based on if it is a full range or a partial 10k block
312 314 0000-1999
312 314 5000-5999
would set the frange to F
When I do a ps -ef I kill the process that shows my
cat $fileloc2 |while read line
The script continues on at that point, but not where it left off. Which seems like the cat $fileloc is still working.
Looks as though there was some type of file contention, I simply decided to pipe the sed statements together and everything worked like a charm.
<Orig>
sed '0001,'$erange'!d' $hfile > $temp
sed 's/NPANXX/'$npanxx'/g;s/XXNAPN/'$revnpa'/g;s/Y/I/g' $temp >> $tempfile
<new>
sed '0001,'$erange'!d' $hfile | sed 's/NPANXX/'$npanxx'/g;s/XXNAPN/'$revnpa'/g;s/Y/I/g' >> $tempfile