exclude lines in a loop

I use while do - done loop in my shell script. It is working as per my expectations.
But I do not want to process all the lines. I am finding it difficult to exclude certain lines.

1) I do not want to process blank lines as well as lines those start with a space " "
2) I do not want to process the headings. The headlines start with the word AGENT or PRODUCT or TOTAL

Any help will be appreciated.

You can try something like this (and maybe you can do the whole processing with awk):

awk '!/^ / && !/^$/ && !/^AGENT/ && !/^PRODUCT/ && !/^TOTAL/' file | 
while read line
do
  echo "$line"
  ....
done

Regards

Hello there,

I think the following KornShell script can do the job

#!/bin/ksh

IFS='
'

while read LINE
do
    
    for TOKEN in $LINE
    do
        UPPER=$(print $TOKEN | tr '[a-z]' '[A-Z]')
        if [[ ($UPPER = +([     ])*) ||
              ($UPPER = *([     ])+(TOTAL|AGENT|PRODUCT)*) ]]
        then
            continue
        else
            #     And here you put all
            #     instructions to process the input
            #     don't forget the following break
            break
        fi
    done
    
done < $1

Actually, because here you ignore also the space character, you will need to modify the default IFS. In fact, the space characters (and I suppose the tabs) must be omitted. The IFS containing only the new line character is defined in the following way

IFS='
'

If you just write something like $'\n' or "\n" it doesn't work. The same is true about tabs. If you want to define a pattern including one or several space/tab characters you have to write [ ], that is, after [ you put a space character and then you push the tab key before closing ] (if instead of doing that you write \t it will not work)

I hope this can help

Regards,
:slight_smile: