Bash scripts to find out missing lines and common lines between two files

Sometime back I had explained how to find the difference and common lines in two files, Using that giving you 2 simple (very simple) scripts

1. Find out the missing lines between two files

cat diff.sh

#!/bin/bash
if [ $# -eq 0 ];then
        echo "No arguemnts given; Usage : ./diff file2 file1"
        exit 1
fi
echo "Lines exist in $2 and not in $1 are :"
grep -Fxv -f $1 $2

2. Find out the common lines between two files

cat common.sh

#!/bin/bash
if [ $# -eq 0 ];then
        echo "No arguments given; Usage : ./common file1 file2"

        exit 1
fi
echo "Common files in $1 and $2 are :"
awk 'NR==FNR{a[$1]++;next} a[$1] ' $1 $2

Enjoy 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s