This is my function in UNIX file. In this function I am
-> first replacing spaces in character 19-27 with 0
-> then if it's all zeros ( 9 zeros) replace it with space
The reason I have to make it to 0 first is that my requirement is that if this field is having value of 0 , replace it with spaces. The zeros in coming in various ways like-
All zeros. (000000000)
Spaces in between. (0000 0)
Only 1 zero.( 0)
This function is taking 2 minutes 25 seconds for 2000 records which is very very slow. We can have time window of 25-30 minutes and we can get upto 50000 records in1 day. Could someone suggest some ways to tune this fucntion.
modiify_customer_feed_id()
{
while IFS='' read line
do
f1="$(echo "$line" | cut -c1-18)"
f2="$(echo "$line" | cut -c19-27)"
f3="$(echo "$line" | cut -c28-854)"
f2=$(echo "$f2"|sed 's/ /0/g')
printf "%s%s%s\n" "$f1" "$f2" "$f3"
done < ${SOURCEFILE} > $id_interim_file
echo " ID PROCESS 1 "
while IFS='' read line
do
f1="$(echo "$line" | cut -c1-18)"
f2="$(echo "$line" | cut -c19-27)"
f3="$(echo "$line" | cut -c28-854)"
f2=$(echo "$f2"|sed 's/000000000/ /g')
printf "%s%s%s\n" "$f1" "$f2" "$f3"
done < $id_interim_file > $id_final_file
echo " ID PROCESS 2 "
if [[ $? -ne 0 ]]
then
rm -f $id_interim_file $id_final_file
return 1
else
mv -f $id_final_file $SOURCEFILE
rm -f $id_interim_file
return 0
fi
}