I am attempting to write a script that would read entries from a file (one at a time) and for each entry it should cut the given word from caricature 8 till the 3rd from last character.

I wrote the following

more $TEMP2 | grep join | awk '{print $3}' > $TEMP3
    while read group; do
    {
            LENGTH=`awk '{print length($group)}'`
            LENGTH=$(($LENGTH-2))
            echo $group > $TEMP0
            cut -c8-$LENGTH $TEMP0 >$TEMP4
    }
    done < $TEMP3

But it is not working if I have more then one entry in the file. It looks like it is noot able to load the new $LENGTH value.

Any help would be appreciated.

Thanks

Gal

try:

#!/bin/ksh
# this works under ksh 
# assume TEMP2 TEMP3 TEMP4 are defined
more $TEMP2 | grep join | awk '{print $3}' > $TEMP3
while read group
do
{
   LENGTH=${#group}
   LENGTH=$(($LENGTH-2))
   echo $group > $TEMP0
   cut -c8-$LENGTH $TEMP0 >>$TEMP4
}
done < $TEMP3
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.