How to search words from a column of one file in another file and print matching lines?
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I have two files. For example below:
File 1:
Polaromonas naphthalenivorans
uncultured bacterium
Leptothrix cholodnii
Clostridium clariflavum
Methylocystis parvus
Calditerrivibrio nitroreducens
File 2:
Polaromonas naphthalenivorans 143990 0 6 4 0 0
uncultured bacterium 43393 0 11174 285 0 0
Leptothrix cholodnii 26955 0 0 0 0 0
Clostridium clariflavum 2544 0 3 0 0 2
Met parvus 1603 131 0 0 0 197
Caldi nit 998 831 11 70 7 117
Desired output:
Polaromonas naphthalenivorans 143990 0 6 4 0 0
uncultured bacterium 43393 0 11174 285 0 0
Leptothrix cholodnii 26955 0 0 0 0 0
Clostridium clariflavum 2544 0 3 0 0 2
text-processing grep
add a comment |Â
up vote
0
down vote
favorite
I have two files. For example below:
File 1:
Polaromonas naphthalenivorans
uncultured bacterium
Leptothrix cholodnii
Clostridium clariflavum
Methylocystis parvus
Calditerrivibrio nitroreducens
File 2:
Polaromonas naphthalenivorans 143990 0 6 4 0 0
uncultured bacterium 43393 0 11174 285 0 0
Leptothrix cholodnii 26955 0 0 0 0 0
Clostridium clariflavum 2544 0 3 0 0 2
Met parvus 1603 131 0 0 0 197
Caldi nit 998 831 11 70 7 117
Desired output:
Polaromonas naphthalenivorans 143990 0 6 4 0 0
uncultured bacterium 43393 0 11174 285 0 0
Leptothrix cholodnii 26955 0 0 0 0 0
Clostridium clariflavum 2544 0 3 0 0 2
text-processing grep
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have two files. For example below:
File 1:
Polaromonas naphthalenivorans
uncultured bacterium
Leptothrix cholodnii
Clostridium clariflavum
Methylocystis parvus
Calditerrivibrio nitroreducens
File 2:
Polaromonas naphthalenivorans 143990 0 6 4 0 0
uncultured bacterium 43393 0 11174 285 0 0
Leptothrix cholodnii 26955 0 0 0 0 0
Clostridium clariflavum 2544 0 3 0 0 2
Met parvus 1603 131 0 0 0 197
Caldi nit 998 831 11 70 7 117
Desired output:
Polaromonas naphthalenivorans 143990 0 6 4 0 0
uncultured bacterium 43393 0 11174 285 0 0
Leptothrix cholodnii 26955 0 0 0 0 0
Clostridium clariflavum 2544 0 3 0 0 2
text-processing grep
I have two files. For example below:
File 1:
Polaromonas naphthalenivorans
uncultured bacterium
Leptothrix cholodnii
Clostridium clariflavum
Methylocystis parvus
Calditerrivibrio nitroreducens
File 2:
Polaromonas naphthalenivorans 143990 0 6 4 0 0
uncultured bacterium 43393 0 11174 285 0 0
Leptothrix cholodnii 26955 0 0 0 0 0
Clostridium clariflavum 2544 0 3 0 0 2
Met parvus 1603 131 0 0 0 197
Caldi nit 998 831 11 70 7 117
Desired output:
Polaromonas naphthalenivorans 143990 0 6 4 0 0
uncultured bacterium 43393 0 11174 285 0 0
Leptothrix cholodnii 26955 0 0 0 0 0
Clostridium clariflavum 2544 0 3 0 0 2
text-processing grep
edited Mar 22 at 18:20
don_crissti
46.4k15123153
46.4k15123153
asked Mar 22 at 18:02
Manoj Kumar
12
12
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
grep has this functionality built-in:
grep -Ff file1 file2
means: look for the F
ixed strings from f
ile1 in file2 and report the matching lines from file2.
I am following command but it is showing 0KB. grep -Ff file1.csv file2.csv >out.txt
â Manoj Kumar
Mar 22 at 18:19
then the exact string(s) from file1 are not present in file2. Perhaps there's whitespace at the beginning, middle, or end?
â Jeff Schaller
Mar 22 at 18:21
1
@JeffSchaller and Manoj Kumar, I smell a windowsfile1
with extrar
. What is thefile -i
?
â JJoao
Mar 22 at 18:34
orgrep -q $'x0D' file1.csv && echo carriage returns detected
â Jeff Schaller
Mar 22 at 18:41
File 1 has one column and need to find matching words from file 2.
â Manoj Kumar
Mar 22 at 18:41
 |Â
show 4 more comments
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
grep has this functionality built-in:
grep -Ff file1 file2
means: look for the F
ixed strings from f
ile1 in file2 and report the matching lines from file2.
I am following command but it is showing 0KB. grep -Ff file1.csv file2.csv >out.txt
â Manoj Kumar
Mar 22 at 18:19
then the exact string(s) from file1 are not present in file2. Perhaps there's whitespace at the beginning, middle, or end?
â Jeff Schaller
Mar 22 at 18:21
1
@JeffSchaller and Manoj Kumar, I smell a windowsfile1
with extrar
. What is thefile -i
?
â JJoao
Mar 22 at 18:34
orgrep -q $'x0D' file1.csv && echo carriage returns detected
â Jeff Schaller
Mar 22 at 18:41
File 1 has one column and need to find matching words from file 2.
â Manoj Kumar
Mar 22 at 18:41
 |Â
show 4 more comments
up vote
0
down vote
grep has this functionality built-in:
grep -Ff file1 file2
means: look for the F
ixed strings from f
ile1 in file2 and report the matching lines from file2.
I am following command but it is showing 0KB. grep -Ff file1.csv file2.csv >out.txt
â Manoj Kumar
Mar 22 at 18:19
then the exact string(s) from file1 are not present in file2. Perhaps there's whitespace at the beginning, middle, or end?
â Jeff Schaller
Mar 22 at 18:21
1
@JeffSchaller and Manoj Kumar, I smell a windowsfile1
with extrar
. What is thefile -i
?
â JJoao
Mar 22 at 18:34
orgrep -q $'x0D' file1.csv && echo carriage returns detected
â Jeff Schaller
Mar 22 at 18:41
File 1 has one column and need to find matching words from file 2.
â Manoj Kumar
Mar 22 at 18:41
 |Â
show 4 more comments
up vote
0
down vote
up vote
0
down vote
grep has this functionality built-in:
grep -Ff file1 file2
means: look for the F
ixed strings from f
ile1 in file2 and report the matching lines from file2.
grep has this functionality built-in:
grep -Ff file1 file2
means: look for the F
ixed strings from f
ile1 in file2 and report the matching lines from file2.
answered Mar 22 at 18:15
Jeff Schaller
31.2k846105
31.2k846105
I am following command but it is showing 0KB. grep -Ff file1.csv file2.csv >out.txt
â Manoj Kumar
Mar 22 at 18:19
then the exact string(s) from file1 are not present in file2. Perhaps there's whitespace at the beginning, middle, or end?
â Jeff Schaller
Mar 22 at 18:21
1
@JeffSchaller and Manoj Kumar, I smell a windowsfile1
with extrar
. What is thefile -i
?
â JJoao
Mar 22 at 18:34
orgrep -q $'x0D' file1.csv && echo carriage returns detected
â Jeff Schaller
Mar 22 at 18:41
File 1 has one column and need to find matching words from file 2.
â Manoj Kumar
Mar 22 at 18:41
 |Â
show 4 more comments
I am following command but it is showing 0KB. grep -Ff file1.csv file2.csv >out.txt
â Manoj Kumar
Mar 22 at 18:19
then the exact string(s) from file1 are not present in file2. Perhaps there's whitespace at the beginning, middle, or end?
â Jeff Schaller
Mar 22 at 18:21
1
@JeffSchaller and Manoj Kumar, I smell a windowsfile1
with extrar
. What is thefile -i
?
â JJoao
Mar 22 at 18:34
orgrep -q $'x0D' file1.csv && echo carriage returns detected
â Jeff Schaller
Mar 22 at 18:41
File 1 has one column and need to find matching words from file 2.
â Manoj Kumar
Mar 22 at 18:41
I am following command but it is showing 0KB. grep -Ff file1.csv file2.csv >out.txt
â Manoj Kumar
Mar 22 at 18:19
I am following command but it is showing 0KB. grep -Ff file1.csv file2.csv >out.txt
â Manoj Kumar
Mar 22 at 18:19
then the exact string(s) from file1 are not present in file2. Perhaps there's whitespace at the beginning, middle, or end?
â Jeff Schaller
Mar 22 at 18:21
then the exact string(s) from file1 are not present in file2. Perhaps there's whitespace at the beginning, middle, or end?
â Jeff Schaller
Mar 22 at 18:21
1
1
@JeffSchaller and Manoj Kumar, I smell a windows
file1
with extra r
. What is the file -i
?â JJoao
Mar 22 at 18:34
@JeffSchaller and Manoj Kumar, I smell a windows
file1
with extra r
. What is the file -i
?â JJoao
Mar 22 at 18:34
or
grep -q $'x0D' file1.csv && echo carriage returns detected
â Jeff Schaller
Mar 22 at 18:41
or
grep -q $'x0D' file1.csv && echo carriage returns detected
â Jeff Schaller
Mar 22 at 18:41
File 1 has one column and need to find matching words from file 2.
â Manoj Kumar
Mar 22 at 18:41
File 1 has one column and need to find matching words from file 2.
â Manoj Kumar
Mar 22 at 18:41
 |Â
show 4 more comments
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f432890%2fhow-to-search-words-from-a-column-of-one-file-in-another-file-and-print-matching%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password