Comparing two files in linux terminal

后端 未结 10 1188
一生所求
一生所求 2020-12-22 17:31

There are two files called \"a.txt\" and \"b.txt\" both have a list of words. Now I want to check which words are extra in \"a.txt\

10条回答
  •  别那么骄傲
    2020-12-22 18:06

    You can use diff tool in linux to compare two files. You can use --changed-group-format and --unchanged-group-format options to filter required data.

    Following three options can use to select the relevant group for each option:

    • '%<' get lines from FILE1

    • '%>' get lines from FILE2

    • '' (empty string) for removing lines from both files.

    E.g: diff --changed-group-format="%<" --unchanged-group-format="" file1.txt file2.txt

    [root@vmoracle11 tmp]# cat file1.txt 
    test one
    test two
    test three
    test four
    test eight
    [root@vmoracle11 tmp]# cat file2.txt 
    test one
    test three
    test nine
    [root@vmoracle11 tmp]# diff --changed-group-format='%<' --unchanged-group-format='' file1.txt file2.txt 
    test two
    test four
    test eight
    

提交回复
热议问题