Operating System - HP-UX
1833648 Members
4554 Online
110062 Solutions
New Discussion

help with this script requirement

 
sapna.sun
New Member

help with this script requirement

The main aim of this script is to find a diff between old code file and new code file , and merge the new code into the old code.
6 REPLIES 6
Steven E. Protter
Exalted Contributor

Re: help with this script requirement

Shalom,

The first part is easy if the code is in a text file.

diff

You can route that into a file and take actions to insert the code into a new file with tools like sed

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
James R. Ferguson
Acclaimed Contributor

Re: help with this script requirement

Hi:

Have a look at the manpages for 'diff' :

http://docs.hp.com/en/B2355-60130/diff.1.html

There are even examples for you therein.

Regards!

...JRF...
Raj D.
Honored Contributor

Re: help with this script requirement

sapna,
You can use # sdiff -b oldcode newcode
view the difference and parse that output & combine a new file with updated code.

Check this out if you are looking something like this:,
http://bash.cyberciti.biz/file-management/send-http-code-301-moved-permanently-redirection/

If you have any example it would be great,

Hth,
Raj.
" If u think u can , If u think u cannot , - You are always Right . "
James R. Ferguson
Acclaimed Contributor

Re: help with this script requirement

Hi (again):

In keeping with the Perl philosophy that "There Is More Than One Way To Do It" (TIMTOWTDI) I should add that you can use the output of 'diff' with the 'ed' command (as documented in the 'diff' manpages) _OR_ you can use the 'patch' utility, written by Larry Walls --- the creator of Perl itself.

Consider these two files:

# cat ./f1
#!/usr/bin/sh
[ "$#" = 0 ] && echo "arg required"
echo "you passed: '$@'"
exit 0

# cat ./f2
#!/usr/bin/sh
[ "$#" = 0 ] && { echo "arg required"; exit 1; }
echo "you passed: '$@'"
echo "nice work..."
exit 0

Now create a patch from the differences of the files:

# diff -e f1 f2 > mypatch

...add a "w"rite command for use with 'ed':

# echo w >> mypatch
# cp f1 f1.old
# ed f1 < mypatch

The 'f1' file is now identical to 'f2'.

Another way is to use 'patch'. Begin again using the original 'f1' and 'f2' files in this example:

# diff -e f1 f2 > mypatch #...as before...
# UNIX95= patch -e -i mypatch -o f1.new f1

Now you have a modified copy of 'f1' as 'f1.new' which matches 'f2'. Notice that no "w" character was appended to the 'mypatch' file created by 'diff' when the objective was to use 'patch'.

Notice too, that we set UNIX95 (XPG4) behavior to use the '-i' option of 'patch'. There is whitespace after the "UNIX95=" and before the "patch" command. There is no semicolon! This keeps UNIX95 set only for the duration of the command line. To do otherwise may lead to behavior your don't expect.

Regards!

...JRF...

James R. Ferguson
Acclaimed Contributor

Re: help with this script requirement

HI (again):

Oops, the author of 'patch' and the author or Perl was Larry Wall. It is Larry Wall's work of which I spoke :-) Never change a sentence in mid-stream without really, really proof-reading.


...JRF...
Arturo Galbiati
Esteemed Contributor

Re: help with this script requirement

Hello,
why not use the rcs feature between version?

HTH,
Art