Print lines in one file matching patterns in another file

后端 未结 5 953
-上瘾入骨i
-上瘾入骨i 2020-11-29 06:45

I have a file with more than 40.000 lines (file1) and I want to extract the lines matching patterns in file2 (about 6000 lines). I use grep like this, but it is very slow: <

5条回答
  •  执笔经年
    2020-11-29 07:27

    Just for the sake of learning: I was solving the same problem and I came up with various solutions (including read $line loops etc..). When I got to the grep one-liner found above, I still ended up getting the wrong output. Then I realized my PATTERN file had 2 trailing lines... So grep picked up all my lines from my database. Morality: check you trailing spaces/lines. Also, ran the command on a much larger dataset with several hundreds patterns and time couldn't even count.

提交回复
热议问题