1828227 Members
3099 Online
109975 Solutions
New Discussion

COM file to do DIFF

 
SOLVED
Go to solution
Jdavid
New Member

COM file to do DIFF

Hey all,

I'm new to DCL and OpenVMS and am trying to create a COM file that could do a DIFF between 2 versions of a file, for all the files in a directory.

Is this possible?, or is there any code/script out there that does this already?

Thanks
5 REPLIES 5
Jan van den Ende
Honored Contributor
Solution

Re: COM file to do DIFF

Jdavid,

to begin with:

Welcome to OpenVMS, and to the Forum!

$ HELP LEX is your friend here.

Try something along this line:

$loop:
$ next = f$search("")
$ if next .eqs. "" then goto done
$ diff 'next' /output =
$ goto loop
$done:

Well, you will have to do all error handling and other niceties yourself. I can eg thing of files with no lower version?

Please use HELP: after 25 years it still is MY friend!

Success.

Proost.

Have one on me.

jpe
Don't rust yours pelled jacker to fine doll missed aches.
Hein van den Heuvel
Honored Contributor

Re: COM file to do DIFF

Hi there,

Welcome to the HP ITRC OpenVMS forum.

Here is a script to get you going:

$loop:
$file = f$search("*.tmp;0",1)
$if file.eqs."" then exit
$older = f$elem(0,";",file) + ";-1"
$!write sys$output file, " ", older
$if "".eqs. f$search(older,2) then goto loop
$diff 'file
$goto loop

It does two 'fancy' things.

1) it uses special file version naming.
To get only the highest version of what might be many files it uses ";0" thus the script does not need to match for other files with the same name but different version. And to see whether a diff is needed it searches for version ;-1 that being the next older version if present.

2) it uses CONTEXT for F$SEARCH such that the main one used to loop through all the files, does nto get confused by the one to test for an older version


be sure to use VMS HELP on all construct in the exampel to fully comprehend.

$HELP LEXI F$SEARCH
$HELP LEXT F$ELEMENT
:

Enjoy DCL,
Hein van den Heuvel


Joseph Huber_1
Honored Contributor

Re: COM file to do DIFF

Best would be to get one of the general "operate on a list of files" command-files from some freeware archive. The best IMHO is EACH.COM (on dcl.openvms.org ? , if not, my copy is at http://wwwvms.mppmu.mpg.de/util_root/com/each.com )
Then the stuff is rather easy:
$ EACH *.*;0 "DIFFERENCE 'n'"

But for a list of files, You probably want to do something with the files if they are (not-)identical:
some examples how to do things after comparisons are in my command-files like
DELETE_IF_IDENTICAL.COM
COPY_IF_DIFFERENT.COM
on the http page above.
http://www.mpp.mpg.de/~huber
Hein van den Heuvel
Honored Contributor

Re: COM file to do DIFF

Joseph is correct.
It is kinda nice to have a generic 'do this action for this list of files script'.


Also, John Gillings pointed out to me that the following line is too quick & dirty in my script:

$ older = F$PARSE(";-1",file) + ";-1"

The problem is of course files with ";" somewhere else in the name. And for other cases perhaps the usage of "." as version indicator. I frequently do things like: delete x.tmp.

The proper way to solve this with learning as little as possible about file name parsing yourself is:

$ older = F$PARSE(";-1",file)

Correct. And shorter :-)

Runner up might be:

older = file - f$parse(file,,,"version") + ";-1"

I only show that to show the power of string substractions and appends. The straight parse is better.

Cheers,
Hein.






Joseph Huber_1
Honored Contributor

Re: COM file to do DIFF


By the way, EACH together with PIPE allows to do something like:

each *.com;-1 "pipe diff 'nt'/nooutput ; if $SEVERITY.eq.1 then delete/log 'nt';0"

to delete the newest identical versions of files.
http://www.mpp.mpg.de/~huber