Saturday, September 13, 2008

Comparing two columns

#! /bin/ksh

########################
### Created on : 10-sep-2008 ###
### Created By : Manu Swami ###
#########################

############## How to use -- USAGE ###############

usage="$0 File1 File2"

############ Setting up the environment variables #####################

datetime=`date '+%Y%m%d'`
export FILE1="$1"
export FILE2="$2"

########## If either of the mandatory parameters is missing raise error #############

if [[ "$FILE1" = "" ]] || [[ "$FILE2" = "" ]] then
print "Invalid usage, Usage is : "
print "$usage"
exit 1
fi
############################################################

echo "\n"
echo "#### Contents of "$1" which are not present in "$2" ####"
for i in $(cat "$1")
do

cat "$2" | grep "^"$i"$">check.txt

if [ -s check.txt ]
then
cat check.txt>>result.txt
else
echo "Not found --> "$i" : in the file "$2".."
fi

done

echo "\n"
echo "#### Contents of "$2" which are not present in "$1" ####"
for j in $(cat "$2")
do

cat "$1" | grep "^"$j"$">checkf.txt

if [ -s checkf.txt ]
then
cat checkf.txt>>result.txt
else
echo "Not found --> "$j" : in the file "$1".."
fi

done

echo "\n"
echo "Cleaning up temporary files, if there is any...."
rm result.txt
rm check.txt
rm checkf.txt
echo "Temp Section cleaned."

echo "\n"

1 comment:

javin paul said...

Nice article , you have indeed cover the topic with great details. I have also blogged my experience as 5 example of symbolic link or symlink in unix . let me know how do you find it

 

Blogger news

Blogroll