[vox-tech] BASH: ignore space in for loop
Dylan Beaudette
dylan at iici.no-ip.org
Wed Oct 20 12:33:25 PDT 2004
Hi --
Can't seem to figure out how to make this BASH script do what I would like it
to do:
I have 2 files:
file A:
Name of place 1
Name of place 2
...
file B:
Name of place 1 [tab] code1
Name of place 1 [tab] code1
...
The "Name of place" values often have spaces in them, which seems to be
confusing a for loop in bash:
running:
for this_quadname in `cat file_a`; do echo grep -i "$this_quadname" file_b ;
done
produces this:
grep -i 'Name' file_b
grep -i 'of' file_b
grep -i 'place' file_b
...so it would seem that the for loop is iterating over both spaces AND
newlines in the `cat file_a` expression...
is there any way to make bash only iterate over the newline characters?
thanks in advance for any ideas!
PS I am merely trying to implement a simple many-to-one join on 2 text files
based on a common key, which is the first column in each file... however the
spaces in the keys are messing up the conventional 'join' program...
Dylan
More information about the vox-tech
mailing list