for me it does not work, with the actual files i have.
That is why i wrote "strange" in the beginning. I've run it before and it worked fine
but i do not know what could be wrong now.
I created exactly the files with the given names and content...
So start to see if the cat command part works or check your perms on those files try to give var name using UPPERCASE which will prevent you to having to look for reseved words or aliases...
Yes first example does not work because its a non sence...
read command reads something, a VAR a line from input ( and so cant read a file, but cat does...)
I mean by uppercase e.g.
cat file1.txt|while read LINE; do echo -e "$LINE";done
Addendum...
I ment depending from where you come from and what keyboard layout you have, you may not choose the correct one... For the only reason I saw at that time for the line to not work was the | (for me here it would be AltGr+ 7 keys to depress)
Corona688:
You are absolutely right but that, our member already knows and tried ( see the beginning of thread...and I also sugggested was better...) but what he could not understand what was incorrect in his example giving a
read VAR <a file>
Maybe could you explain to our guest the reason or how works the redirection ( I wonder if its not there the confusion - where in input using < you specify a file, but doesnt work with read <variable> file...)
It may sound silly but, since i want to use grep i actually want two input files, file1.txt and file2.txt
How do I do this? I mean in my case the command
cat file1.txt|while read line; do grep "$line" file2.txt;done
does not give me result. When i use the < though to set the input file it works.
So i wonder how can i do this with my two input files?
I hope i am not very confusing but i have no idea why WITH THE PARTICULAR FILES it does not work
ran:/home/vbe $ ll -lt|grep file
-rw-rw-rw- 1 vbe bin 51 Sep 20 16:55 file2.txt
-rw-rw-rw- 1 vbe bin 17 Sep 20 16:55 file1.txt
-rw-rw-rw- 1 vbe bin 44 Nov 11 2010 filename
ran:/home/vbe $ cat file*txt
angie
mary
susan
angie blond
mary brunnet
susan red
christine black
ran:/home/vbe $ cat file1.txt|while read line ;do grep "$line" file2.txt;done
angie blond
mary brunnet
susan red
ran:/home/vbe $
I suggest that the OP provide an unambiguous dump of his/her text file, using hexdump -C, od -bc, or whatever tool is available to give us a definitive manifest of the files' contents.
The following is an example of data that appears fine when sent to the terminal but thwarts grep's attempt to match it:
Also, it wouldn't hurt to post a trace of your shell's actions. Assuming you're using a posix-like shell, you can probably enable tracing with set -x (you can then disable it with set +x ).
So you do the same: do a copy paste if you can from your post, dont edit just copy /paste straight to your unix box but can you ? (Im using ReflectionX...).