What are you trying to accomplish? From the way that this is presented, it looks like homework - and that is not allowed per the Forum Rules. The UNIX and Linux Forums - Forum Rules
iam new to shell script, & i tried the below code.
#!/bin/bash #To compare the password file
echo "File comparision"
awk -F';' 'BEGIN{while(getline<"file1") a[$1]=2};a[$1]!=2' file2> listdifference
cksum file1 | awk '{print$1}' > x
cksum file2 | awk '{print$1}' > y
x=`cat x`
y=`cat y`
function test
{
if [ $x -le $y ]
then
echo "First file x is smaller. Add difference into smaller file x and remove the difference."
while read difference
do
echo "Deleting line $difference" #sed "/$difference/d" listfinal > output
sed -e "s/$difference//g" listfinal > output
done < listdifference
else
echo "Second file y is bigger. Add line into x."
fi
}
test
--------------
after running the above script i got the below list to the listdifference file.
yellow:sujji
blue:summi
orange:girri
red:akash
white:alias
but i need is if any changes are made in the file2 that has the entries in file1 i need to replace that entry in file1 with the value of file2.
ex: in file1 we have an entry called 'yellow:sure' if i changed the value of the same in file2 to 'yellow:somethingelse' then it has to replace with the same in file1 for the value of 'yellow:sure' .
Thank you, the code provided by you people are working fine if the lines in both the files are in same order. but if the lines are not in same arder it fails.