Skip to main content
Became Hot Network Question
Rollback to Revision 2
Source Link
AdminBee
  • 23.6k
  • 25
  • 55
  • 77

Is it possible to use the multi-line output of a grep run of one file as patterns for use with a subsequent second grep run on another file?

Example:

  • content of file1.txt
    2 blue
    1 red 
    1 green
    2 black
    2 orange
    
  • content of file2.txt
    2 blue triangle
    2 blue circle
    3 blue triangle
    2 red triangle
    3 green circle
    4 red square
    2 orange circle
    2 brown circle
    
  • Result of first grep:
    $ grep 2 file1.txt 
    
    2 blue 
    2 black
    2 orange
    

Now, I am looking for a command that implements something like

grep <PREVIOUS OUTPUT> file2.txt

that would find all lines in file2.txt that start with one of the lines produced by the grep run on file1.txt, so the desired result is:

2 blue triangle
2 blue circle
2 orange circle

Solved:

grep 2 file1.txt  | xargs   -I{} grep  {}   file2.txt

2 blue triangle
2 blue circle
2 orange circle

Is it possible to use the multi-line output of a grep run of one file as patterns for use with a subsequent second grep run on another file?

Example:

  • content of file1.txt
    2 blue
    1 red 
    1 green
    2 black
    2 orange
    
  • content of file2.txt
    2 blue triangle
    2 blue circle
    3 blue triangle
    2 red triangle
    3 green circle
    4 red square
    2 orange circle
    2 brown circle
    
  • Result of first grep:
    $ grep 2 file1.txt 
    
    2 blue 
    2 black
    2 orange
    

Now, I am looking for a command that implements something like

grep <PREVIOUS OUTPUT> file2.txt

that would find all lines in file2.txt that start with one of the lines produced by the grep run on file1.txt, so the desired result is:

2 blue triangle
2 blue circle
2 orange circle

Solved:

grep 2 file1.txt  | xargs   -I{} grep  {}   file2.txt

2 blue triangle
2 blue circle
2 orange circle

Is it possible to use the multi-line output of a grep run of one file as patterns for use with a subsequent second grep run on another file?

Example:

  • content of file1.txt
    2 blue
    1 red 
    1 green
    2 black
    2 orange
    
  • content of file2.txt
    2 blue triangle
    2 blue circle
    3 blue triangle
    2 red triangle
    3 green circle
    4 red square
    2 orange circle
    2 brown circle
    
  • Result of first grep:
    $ grep 2 file1.txt 
    
    2 blue 
    2 black
    2 orange
    

Now, I am looking for a command that implements something like

grep <PREVIOUS OUTPUT> file2.txt

that would find all lines in file2.txt that start with one of the lines produced by the grep run on file1.txt, so the desired result is:

2 blue triangle
2 blue circle
2 orange circle
added 143 characters in body
Source Link

Is it possible to use the multi-line output of a grep run of one file as patterns for use with a subsequent second grep run on another file?

Example:

  • content of file1.txt
    2 blue
    1 red 
    1 green
    2 black
    2 orange
    
  • content of file2.txt
    2 blue triangle
    2 blue circle
    3 blue triangle
    2 red triangle
    3 green circle
    4 red square
    2 orange circle
    2 brown circle
    
  • Result of first grep:
    $ grep 2 file1.txt 
    
    2 blue 
    2 black
    2 orange
    

Now, I am looking for a command that implements something like

grep <PREVIOUS OUTPUT> file2.txt

that would find all lines in file2.txt that start with one of the lines produced by the grep run on file1.txt, so the desired result is:

2 blue triangle
2 blue circle
2 orange circle

Solved:

grep 2 file1.txt  | xargs   -I{} grep  {}   file2.txt

2 blue triangle
2 blue circle
2 orange circle

Is it possible to use the multi-line output of a grep run of one file as patterns for use with a subsequent second grep run on another file?

Example:

  • content of file1.txt
    2 blue
    1 red 
    1 green
    2 black
    2 orange
    
  • content of file2.txt
    2 blue triangle
    2 blue circle
    3 blue triangle
    2 red triangle
    3 green circle
    4 red square
    2 orange circle
    2 brown circle
    
  • Result of first grep:
    $ grep 2 file1.txt 
    
    2 blue 
    2 black
    2 orange
    

Now, I am looking for a command that implements something like

grep <PREVIOUS OUTPUT> file2.txt

that would find all lines in file2.txt that start with one of the lines produced by the grep run on file1.txt, so the desired result is:

2 blue triangle
2 blue circle
2 orange circle

Is it possible to use the multi-line output of a grep run of one file as patterns for use with a subsequent second grep run on another file?

Example:

  • content of file1.txt
    2 blue
    1 red 
    1 green
    2 black
    2 orange
    
  • content of file2.txt
    2 blue triangle
    2 blue circle
    3 blue triangle
    2 red triangle
    3 green circle
    4 red square
    2 orange circle
    2 brown circle
    
  • Result of first grep:
    $ grep 2 file1.txt 
    
    2 blue 
    2 black
    2 orange
    

Now, I am looking for a command that implements something like

grep <PREVIOUS OUTPUT> file2.txt

that would find all lines in file2.txt that start with one of the lines produced by the grep run on file1.txt, so the desired result is:

2 blue triangle
2 blue circle
2 orange circle

Solved:

grep 2 file1.txt  | xargs   -I{} grep  {}   file2.txt

2 blue triangle
2 blue circle
2 orange circle
Formatting, re-tag
Source Link
AdminBee
  • 23.6k
  • 25
  • 55
  • 77

Is it possible to filter a grep withuse the multi-line output of another grepa grep run of one file as patterns for use with several linesa subsequent second grep run on another file?

Example:

content of file1.txt

2 blue
1 red 
1 green
2 black
2 orange

content of file2.txt

2 blue triangle
2 blue circle
3 blue triangle
2 red triangle
3 green circle
4 red square
2 orange circle
2 brown circle
  • content of file1.txt
    2 blue
    1 red 
    1 green
    2 black
    2 orange
    
  • content of file2.txt
    2 blue triangle
    2 blue circle
    3 blue triangle
    2 red triangle
    3 green circle
    4 red square
    2 orange circle
    2 brown circle
    
  • Result of first grep:
    $ grep 2 file1.txt 
    
    2 blue 
    2 black
    2 orange
    

grep 2 file1.txtNow, I am looking for a command that implements something like

2 blue 
2 black
2 orange
grep <PREVIOUS OUTPUT> file2.txt

and filter that output inside file2.txt like "grep PREVIOUS OUTPUT file2.txt" withwould find all lines in file2.txt that start with one of the lines produced by the grep run on file1.txt, so the desired result is:

2 blue triangle
2 blue circle
2 orange circle
2 blue triangle
2 blue circle
2 orange circle

Is it possible to filter a grep with the output of another grep with several lines?

Example:

content of file1.txt

2 blue
1 red 
1 green
2 black
2 orange

content of file2.txt

2 blue triangle
2 blue circle
3 blue triangle
2 red triangle
3 green circle
4 red square
2 orange circle
2 brown circle

grep 2 file1.txt

2 blue 
2 black
2 orange

and filter that output inside file2.txt like "grep PREVIOUS OUTPUT file2.txt" with result:

2 blue triangle
2 blue circle
2 orange circle

Is it possible to use the multi-line output of a grep run of one file as patterns for use with a subsequent second grep run on another file?

Example:

  • content of file1.txt
    2 blue
    1 red 
    1 green
    2 black
    2 orange
    
  • content of file2.txt
    2 blue triangle
    2 blue circle
    3 blue triangle
    2 red triangle
    3 green circle
    4 red square
    2 orange circle
    2 brown circle
    
  • Result of first grep:
    $ grep 2 file1.txt 
    
    2 blue 
    2 black
    2 orange
    

Now, I am looking for a command that implements something like

grep <PREVIOUS OUTPUT> file2.txt

that would find all lines in file2.txt that start with one of the lines produced by the grep run on file1.txt, so the desired result is:

2 blue triangle
2 blue circle
2 orange circle
Source Link
Loading