extract matching lines from File2 based on File1. grep+while?
Hey guys and girls.
Im taking my first steps out into the world of perling, but i think ive jumped in too fast! Im trying to extract matching lines from File2 based on a list in File1 (and then just paste it into File3) Formats: File1 Code:
GP_MASA_01F04_c Code:
GP_MASA_01F04_c,544213...etc I know what Im doing grep wise, so then put a while loop around it yeah? Any help would be much appreciated! Dan |
You don't need Perl for that task -- instead use bash and grep:
for line in `cat "File 1"` ; do grep $line "File 2" ; done |
How does that get it into file3?
|
Why to not simply use the -f option of grep?
Code:
grep -f file1 file2 > file3 |
cheers for all the replies guys. didnt realise i could use a txt list as an input into grep. but still, using your:
Code:
grep -f file1 file2 > file3 (btw, im using the -v flag because i want all the lines that arent in the file1 deffinition file) so now my cmd looks: Code:
grep -v -f file1 file2 > file3 |
I noticed in the File 1 you pasted in your previous post, you had a trailing blank space at the end of each line. If this is the case, try to remove them. I reproduced your situation and it works quite well for me.
|
All times are GMT -5. The time now is 09:02 AM. |