Using korn shell. I am reading a file line by line. If a record has a carriage return (octal 015) then I append the second record to the first record. Not all records have a carriage return. I have the unix shell script working with grep, but when my file has +100,000 records it runs slow. I would like to see if the shell script would run faster with an IF Test or AWK. I can't get the syntax right for the IF test. I don't know AWK, if you think this would run faster I would appreciate know how to code it.
1) I was doing some time testing to see where my shell script was slow. This runs fast.
#!/bin/ksh
file_in=file.txt
file_out=file.txt_out
cnt_in=0
while read LINE
do
cnt_in=$(( cnt_in + 1 ))
echo $LINE >> $file_out
done < $file_in
2) This runs slow
#!/bin/ksh
dir1=/tdcexports/db2/stage
file_in=file.txt
file_out=file.txt_out
cnt_in=0
while read LINE
do
cnt_in=$(( cnt_in + 1 ))
ck_carriage=`echo $LINE | grep -c ^M`
echo $LINE >> $file_out
done < $file_in
3) I've tried various IF but didn't find the right syntax yet. This doesn't work properly:
if [ $LINE = '\015' ]
then echo equal
else echo no equal
fi
Thank you for your help.