Trouble with a file path as awk output in for loop

When I run the following command in the shell it works fine. It prints a city name and then a path for a file.

~$ for i in `awk -F':' '{print $0}' /home/knoppix/Desktop/data/subs | grep -m 1 $ city | sed "s/:/ /"`
>do
>echo $i
>done

Now, when I place it in this shell script (sh) it prints the first entry, a city name, but it just give me blank for the path.

for sub in `awk -F':' '{print $0}' $datsub | grep -m 1 $city | sed "s/:/ /"g`
do

if [ "`echo $sub`" == "`echo $city `" ]
then
echo "Substituting files in $projectname now"

elif [ "`echo $sub | grep .jpg`" ]
then
cp -r $sub $projectname/images
echo "$sub replaced"

elif [ "`echo $sub | grep .gif`" ]
then
cp -r $sub $projectname/images
echo "$sub replaced"

elif [ "`echo $sub | grep .png`" ]
then
cp -r $sub $projectname/images
echo "$sub replaced"

else
cp -r $sub $projectname
echo "$sub replaced"
fi
done

I'm really confused as to why. I know it's getting to the entry, I don't know why it's printing blank. I even tried escaping the "/" characters and all it did was print them as well.

The subs file is written like:

City1:/home/knoppix/subs/file1
City2:/home/knoppix/subs/file2
City3:/home/knoppix/subs/file3
...

Sorry but this is nonsense, maybe you try to win the Useless Use of Cat Award :wink:

oIFS=IFS
IFS=":" 
while read city path
    do 
          echo $city $path
          # Insert your IF's here
done < sub.file
IFS=$oIFS 

no need for the oIFS:

while IFS=: read city path
    do 
          echo $city $path
          # Insert your IF's here
done < sub.file

Just in case :rolleyes:

Yea, it looks that way, but it worked. I just removed the -r from in front of the cp commands.

I'm always trying to learn though. Are those awk scripts?

No it is shell script only

Wow, well I need to hit the books.