Home > database >  How to find differences over one file to another in Linux
How to find differences over one file to another in Linux

Time:05-23

File1.txt

Mango
Oranges

File2.txt

Mango
Apple

I want to find differences over one file to the another. I am expecting the output as

oranges

I want to compare file1 different from file2. What exists in file1 but not in file2. I have used diff file1.txt file2.txt it’s giving me all different values between both files

CodePudding user response:

You can use comm

comm -23 \
    <(cat File1.txt | tr '[:upper:]' '[:lower:]' | sort -u) \
    <(cat File2.txt | tr '[:upper:]' '[:lower:]' | sort -u)
oranges

Or awk

awk '
    {
        w = tolower($0)
    }
    FNR == NR {
        words[w]  
        next
    }
    w in words {
        delete words[w]
    }
    END {
        for (w in words)
            print w
    }
' File1.txt File2.txt
oranges
  • Related