Find the similarities between two files

后端 未结 2 1186
独厮守ぢ
独厮守ぢ 2020-12-07 00:02

I have two file like:

1
2
3
4
5
6
7
8
9
10

and a file with two columns

1 0.11
2 0.12748
5 0.45
12 0.48
7 0.48
8 0.7
13 0.78         


        
2条回答
  •  一整个雨季
    2020-12-07 00:34

    You can use grep -f patt_file file to get the patterns from a file. That is, search in file patterns included in patt_file.

    See the output with your given input:

    $ grep -w -f file1 file2
    1 0.11
    2 0.12748
    5 0.45
    7 0.48
    8 0.7
    

    From man grep:

    -f FILE, --file=FILE

    Obtain patterns from FILE, one per line. If this option is used multiple times or is combined with the -e (--regexp) option, search for all patterns given. The empty file contains zero patterns, and therefore matches nothing.

提交回复
热议问题