![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| total output from a file created in a while loop | Pablo_beezo | Shell Programming and Scripting | 7 | 01-29-2009 11:26 AM |
| Input file redirect in output path and want name as inputfilename_new.txt | Sandeep_Malik | Shell Programming and Scripting | 6 | 09-17-2008 06:16 PM |
| for loop syntax trouble | visitorQ | Shell Programming and Scripting | 9 | 04-13-2008 03:53 AM |
| Loop Trouble | RSymphony | Shell Programming and Scripting | 2 | 11-26-2007 11:50 AM |
| Start more than one database - trouble with for loop | dave-mentor | Shell Programming and Scripting | 5 | 05-30-2006 03:58 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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. Code:
~$ 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. Code:
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: Code:
City1:/home/knoppix/subs/file1 City2:/home/knoppix/subs/file2 City3:/home/knoppix/subs/file3 ... Last edited by afroCluster; 09-30-2009 at 01:12 PM.. Reason: Making it a bit more readible. |
|
||||
|
Quote:
![]() Code:
oIFS=IFS
IFS=":"
while read city path
do
echo $city $path
# Insert your IF's here
done < sub.file
IFS=$oIFS
|
|
|||||
|
Quote:
Code:
while IFS=: read city path
do
echo $city $path
# Insert your IF's here
done < sub.file
|
![]() |
| Bookmarks |
| Tags |
| awk, path, script |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|