grep -f question
Category: UNIX-Unix Beginner
grep -f question
when using grep -f file1 file2
if you have multiple entries in the pattern file1 that are the same will it take the line out of file2 that matches file1 each time it comes up? if not by default can you set a flag to make this possible? or another way - can you get it to search for and match the same pattern more than once?
code:
$ cat file
1111
1111
2345
$ cat file1
1111
7777
$ grep -f file file1
the search is cutting out the doubles - it should be a one for one match all the way down. apparently i am doing something wrong.
say i have file1
1
1
1
3
4
5
and file2
1 hello i am 1
2 hello i am 2
3 hello i am 3
4 hello i am 4
5 hello i am 5
when i grep this grep -f file1 file2 i need the result below
1 hello i am 1
1 hello i am 1
1 hello i am 1
3 hello i am 3
4 hello i am 4
5 hello i am 5
code:
# more file1
1
1
1
3
4
5
# more file2
1 hello i am 1
2 hello i am 2
3 hello i am 3
4 hello i am 4
5 hello i am 5
# join file1 file2
1 hello i am 1
1 hello i am 1
1 hello i am 1
3 hello i am 3
4 hello i am 4
5 hello i am 5
quote:
originally posted by vgersh99
code:
#!/bin/ksh
while read line
do
grep "$line" file2
done < file1
i know this is a pretty simple while loop, but can you explain it?
