Find content of one file from another file in UNIX

前端 未结 8 608
攒了一身酷
攒了一身酷 2020-12-01 07:39

I have 2 files. First file contains the list of row ID\'s of tuples of a table in the database. And second file contains SQL queries with these row ID\'s in \"where\" clause

8条回答
  •  情话喂你
    2020-12-01 08:20

    One way with awk:

    awk -v FS="[ =]" 'NR==FNR{rows[$1]++;next}(substr($NF,1,length($NF)-1) in rows)' File1 File2
    

    This should be pretty quick. On my machine, it took under 2 seconds to create a lookup of 1 million entries and compare it against 3 million lines.

    Machine Specs:

    Intel(R) Xeon(R) CPU E5-2670 0 @ 2.60GHz (8 cores)
    98 GB RAM
    

提交回复
热议问题