All lines should be started with ABC as first field. If a record has another value for 1st field, the previuos record with ABC also an error record. I need to get the output as below
i have written a code by using while ... do ... done. but for bigger files this takes lot of time as this code reads file record by record.
Please help.
My requirement is extract error records. Output shows error records.
My code is
cnt=1
cat input_file | while read line
do
typ=`echo "$line" | cut -c 1-3`
if [ $cnt -gt 1 ]
then
if [ typ != "ABC" ] || [ pre_typ != "ABC" ]
then
echo $pre_line >> output_file
fi
fi
cnt = 2
pre_typ=$typ
pre_line=$line
done
if [ typ != "ABC" ] || [ pre_typ != "ABC" ]
then
echo $pre_line >> output_file
fi
I don't understand what you mean by extract error records,
my code is giving the exact output you wanted (as mentioned in your post)
if you want the output in a file you can just direct the output towards one