I want a shell script program for this purpose and here is my requirement.

I have two files 1.txt and 2.txt

In 1.txt I have the following contents:

label.abcd.1 = asdfgf

label.abcd.2 = qwerqwe

label.abcd.3 = zczxvzx

label.abcd.4 = ;lkjj;l

label.abcd.5 = pupoiup

and in 2. txt I have the following contents

label.abcd.1 = poiuppoiu

label.abcd.3 = iouyiuy

label.abcd.5 = uizxuci

label.abcd.6 = kxkjckvjh

label.abcd.7 = l;kjlkjlj;

Note the contents in 1.txt and 2.txt....... label.abcd.2,4 is removed and label.abcd.6,7 is added newly in 2.txt, and note the righthand side of 1.txt and 2.txt are different.

Now i want the content in 1.txt shd be like this

label.abcd.1 = asdfgf

label.abcd.3 = zczxvzx

label.abcd.5 = pupoiup

label.abcd.6 = kxkjckvjh

label.abcd.7 = l;kjlkjlj;

[label.abcd.6,7 are added and label.abcd.2,4 are removed.] Please Note: The right hand side of label.abcd.1,3,5 are not modified.

This is my requirement. I hope i have not confused u.....

Thanx in advance
Regards,
Naveen. V :)

#!/bin/bash
#
#

cat 2.txt | while read LINE
do
   BUF="`grep \`echo ${LINE} | awk '{ print $1 }'\` 1.txt`"
   if test $? -eq 0
   then
      echo ${BUF}
   else
      echo ${LINE}
   fi
done

Hell Friend!
The above script provided does not work..
Please see the output when i run the script

./mod.sh
label.abcd.1 = poiuppoiu

i have the 1.txt and 2.txt but when i do a cat on 1.txt
it has done nothing!

Thanks for your patience

regards
Whizkidash

Hello whizkidash,


thank you very much for testing!

You're totally right, I oversaw the empty lines in the input file[s].

May you try this one:

#!/bin/bash
#
#

cat 2.txt | while read LINE
do
   if test "" = "${LINE}"
   then
      echo ""
   else
      BUF="`grep \`echo ${LINE} | awk '{ print $1 }'\` 1.txt`"
      if test $? -eq 0
      then
         echo ${BUF}
      else
         echo ${LINE}
      fi
   fi
done > buf.txt
mv buf.txt > 1.txt

Kind regards,
issue9

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.