Read First Character of Each Line in File

I need a better way to read the first character of each line in a file and check if it equals the special character �. This character tells me where there is a break in the reports. The file has over 500,000 lines. Currently, this is my code -

if [[ $(echo $line|cut -c1-1) = "�" ]]

I am using Korn Shell as a scripting language. Is there a better way to do this?

Thank you for your assistance.

I don't know if it will make much difference, but you can try this:

typeset -L1 mOne
while read mLine
do
  mOne=$mLine
done < input_file

Try:

if [ ${line:0:1} = '�' ]
then
  # bingo
fi

Regards

${line:0:1}

works in bash just fine, but not ksh.

Shell_Life's suggestion helped a lot. Processing time went from over 5 hours to 45 minutes. This was the code:

typeset -L1 mOne
while read mLine
do
mOne=$mLine
done < input_file

jim mcnamara was correct that ${line:0:1} would not work.

Thank you for the help.

I apologize, didn't realise that.

Regards

what do you want to do after you have checked the first character equals something?

awk  '/^c/{ do something }' file

It would work if you use the enhanced korn shell (ksh93). For something that takes this long it might be worth testing to see which is faster, assigning it to a one character variable with typeset in the standard korn shell or using the enhanced korn shell's variable substitution. Of course going from 5 hours to 45 minutes is already a pretty nice improvement. :slight_smile: