well!!! the same code I have been using since long time...and it never showed this error....I am executing this on diff flavour of unix.....let me know any other way
---------- Post updated at 12:01 PM ---------- Previous update was at 11:58 AM ----------
cat > abc
for i in `cat tks`
do
grep -i -l $i *.txt | awk -v token=$i '{print token "\t" $0}'
done
Control-D
cat > tks
India Australia America
Control-D
cat -> file1.txt
India and Australia are world champions in cricket
Control-D
cat -> file2.txt
America is NBA champion.
Control-D
Now all files created
at the unix prompt where you run all these files
I'm reminded of something from space history... On opening an electronic module for inspection: "My god, this part passed all our tests and it's *garbage*!" Just because it works doesn't mean it's sensible. And if you use "for stuff in `cat file`" all over the place? You've suddenly got something to worry about.
The error's always been possible, but somehow you've never fed it lines with spaces before, and never fed it files larger than you can squeeze into a variable. You've been lucky.
Because $i wasn't quoted, your awk line ends up awk -v token=India and Australia are world champions in cricket '{print token "\t" $0}' token gets the "india" part. The rest of it -- "and", "australia", "are", "world", "champions", "in", and "cricket" -- awk tries to run as scripts or read as files.
I just did. Try it, it should work. It should be able to handle files of any size too, where your version will barf on files bigger than a few kilobytes on some systems.