Hi All- we have performance issue in unix to read line by line.
I am looking at processing all the records.
description: Our script will read data from a flat file, it will pickup first four character and based on the value it will set up variables accordingly and appended the final output to another flat file as show below.
Concern: script is working fine but we have a performance issue to read line by line, we are looking at something like it will ready all the lines at a time and dynamically identify the first four character and accordingly set up the individual variables and finally append the value.
Please find attached script, sample input data file.
actual script:
---------------------------------------------------------------------------------------
#!/bin/ksh
#set -x
process_each_record()
{
record=$1
###### extract first four characters ##############
record_type=`echo $record | sed 's/\(^....\).*/\1/'`
case $record_type in
1111) a1=100; a2=0; a3=0; a4=0; a5=0; a6=0; a7=0;a8=0; a9=0;
echo "${line_no}${a1}${a2}${a3}${a4}${a5}${a6}${a7}${a8}${a9}${record}" >> test1_all_data.log;
;;
1112) a2=` expr ${a2} + 1 `; a3=` expr ${a3} + 2 `;
echo "${line_no}${a1}${a2}${a3}${a4}${a5}${a6}${a7}${a8}${a9}${record}" >> test1_all_data.log;
;;
1113) a7=` expr ${a7} + 1 `; a5=` expr ${a5} + 3 `;
echo "${line_no}${a1}${a2}${a3}${a4}${a5}${a6}${a7}${a8}${a9}${record}" >> test1_all_data.log;
;;
1114) a4=` expr ${a4} + 3 `; a6=` expr ${a6} + 4 `;
echo "${line_no}${a1}${a2}${a3}${a4}${a5}${a6}${a7}${a8}${a9}${record}" >> test1_all_data.log;
;;
1115) a7=` expr ${a7} + 1 `; a9=` expr ${a9} + 3 `;
echo "${line_no}${a1}${a2}${a3}${a4}${a5}${a6}${a7}${a8}${a9}${record}" >> test1_all_data.log;
;;
1116) a8=` expr ${a8} + 1 `; a5=` expr ${a5} + 1 `;
echo "${line_no}${a1}${a2}${a3}${a4}${a5}${a6}${a7}${a8}${a9}${record}" >> test1_all_data.log;
;;
2221) a6=0; a7=0;a8=0; a9=0;
echo "${line_no}${a1}${a2}${a3}${a4}${a5}${a6}${a7}${a8}${a9}${record}" >> test1_all_data.log;
;;
2222) a3=` expr ${a3} + 1 `; a7=` expr ${a7} + 3 `;
echo "${line_no}${a1}${a2}${a3}${a4}${a5}${a6}${a7}${a8}${a9}${record}" >> test1_all_data.log;
;;
3333) a8=` expr ${a8} + 1 `; a9=` expr ${a9} + 5 `;
echo "${line_no}${a1}${a2}${a3}${a4}${a5}${a6}${a7}${a8}${a9}${record}" >> test1_all_data.log;
;;
5555) a1=` expr ${a1} + 1 `; a2=` expr ${a2} + 3 `; a3=` expr ${a3} + 1 `; a4=` expr ${a4} + 1 `;
echo "${line_no}${a1}${a2}${a3}${a4}${a5}${a6}${a7}${a8}${a9}${record}" >> test1_all_data.log;
;;
*) echo "${line_no}${a1}${a2}${a3}${a4}${a5}${a6}${a7}${a8}${a9}${record}" >> test1_all_data.log;
;;
esac
}
######## define variables #####
typeset -Z10 a1
typeset -Z7 a2
typeset -Z3 a3
typeset -Z6 a4
typeset -Z2 a5
typeset -Z7 a6
typeset -Z9 a7
typeset -Z5 a8
typeset -Z2 a8
typeset -Z4 a9
typeset -Z10 line_no
a1=0; a2=0; a3=0; a4=0; a5=0; a6=0; a7=0;a8=0; a9=0;line_no=0;
if [ -f test1_all_data.log ]
then
rm test1_all_data.log
fi
cat test2.tlog | while read line1
do
line_no=` expr ${line_no} + 1 `
process_each_record ${line1}
done
---------------------------------------------------------------------------------------