-1

I have a text file including 2,000,000 lines (text1) and I want to extract some of the lines just by having some part of the lines(text2). Example:

Text1

seq1 TNS 23 45 67 81 92
seq2 trq 54 67 80 73 12
seq3 ewr 59 61 51 51 71
seq4 qto 54 94 93 92 02

Text2

seq2
seq3
seq4

I need to extract all Text2 inputs from Text1.

any answer will be appreciated, Thanks

Utsav
  • 7,914
  • 2
  • 17
  • 38
Ahmad S
  • 25
  • 4

2 Answers2

3

Use this to match from text1 the lines matching text2

grep -f text2 text1

Here is the example I tried

$> cat text1
seq1 TNS 23 45 67 81 92
seq2 trq 54 67 80 73 12
seq3 ewr 59 61 51 51 71
seq4 qto 54 94 93 92 02

$> cat text2
seq2
seq3
seq4

$> grep -f text2 text1
seq2 trq 54 67 80 73 12
seq3 ewr 59 61 51 51 71
seq4 qto 54 94 93 92 02
Utsav
  • 7,914
  • 2
  • 17
  • 38
0

Construct the matches into a regular expression, and run it through grep:

egrep 'seq2\|seq3\|seq4' Text1
Shachar Shemesh
  • 8,193
  • 6
  • 25
  • 57
  • 1
    Thank you for accepting this answer, but I actually think that @Utsav's answer is better, in that it technically does the same thing, but is easier to implement. – Shachar Shemesh Jul 04 '16 at 09:33