cksum parts of a file


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers cksum parts of a file
# 1  
Old 07-29-2002
cksum parts of a file

Every time we build an executable the date and time are put into the file, I need to run checksum on just the working lines.(IE, no header files)

Is this even possible, if so how would I go about it?

I am using a HP-UX server any help you can give me will be greatly appreciated.

Thanks
# 2  
Old 07-29-2002
I don't think that crazykelso expressed the problem as clearly as possible. Since I also work on HP-UX, I thought that I would explain the problem more fully.

If you have a c program called hello.c and you run:
cc hello.c -o hello1
cc hello.c -o hello2

those two files hello1 and hello2 will be different. If you run cksum or other another checksum program you will get two different results. The difference arises from timestamps that HP-UX puts into the executable. It would be nice to extract the non-timestamp stuff out of an executable and just cksum it.

I don't know of a solution. Smilie
# 3  
Old 07-29-2002
Quote:
Originally posted by Perderabo
I don't know of a solution. Smilie
SmilieYou scare me when you say that!Smilie

Hmmmm...

Is the time-date stamp always the same offset from the beginning of the file and a fixed length? If so, you could copy the entire executable minus the timestamp (leave blank or fill with some character) into a temp file, run CRC32 (MD5, whatever) against it and then do the same with the second file and then compare CRCs to determine if the files are different or not.

I would think that you would have to generate the temp file by fseek'ing byte after byte into the temp binary file leaving out the timestamp. Of course, the temp file probably couldn't be executed but it oughta be good for comparison sake since both files would have had the common timestamp effectively removed.

I tried your example under FreeBSD and md5 reported that both executables were the same so I didn't try any further.
# 4  
Old 07-29-2002
There is one timestamp per compiled module. And the last time that I looked at this, HP didn't document enough of the a.out format to do this. I just learned to live without checksumming executables.

And yes, HP-UX is the only version of unix that I know of with this problem/feature.
# 5  
Old 07-29-2002
Quote:
Originally posted by Perderabo
There is one timestamp per compiled module. And the last time that I looked at this, HP didn't document enough of the a.out format to do this. I just learned to live without checksumming executables.

And yes, HP-UX is the only version of unix that I know of with this problem/feature.
If I were to peruse this further, I would compile hello1 and hello2 and take a gander at where the files were different and eliminate those portions from a compare with the method from the previous post.

The timestamp may not be documented, but crazykelso ought to be able to find the offset and length of the timestamp. But that's with some simple assumptions, like the offset never changes, etc. It would be a neat excercise and if it worked.
# 6  
Old 07-30-2002
Thanks so far

I appreciate your help.

I did a file comparison using a compare tool called: TSBinComp
which is freeware I downloaded from

http://www.screaminet.com/~tswirsky/bincomp.htm

this tool told me that the only differences in the file occur in bytes 223 and 224. If this isn't a reliable tool could someone recomend another one for me?

My next question is, How would I go about removing these two bytes so that I could cksum the two files.

I also did a bdiff and founs that the problem occurs on line fourteen, if it isn't possible to remove those two bytes how would I be able to remove this line or a certain part of this line?

thanks again for your help
crazykelso
# 7  
Old 07-30-2002
I would write a routine in C (or C++) that would open the source files and then fseek offsets from 0 to (n-1) (where n is the length of the file) and just skip over or substitute a common character (say, captial X) for bytes 223 and 224 and write it out to a temporary binary file and run checksum against it and then perform the same with the second file and then compare checksums.

You could probably also write a similiar routine in perl as well but C seems to appropriate.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Split file into n parts.

Hi all: I have a 5-column tab-separated file. The only thing that I want to do with it is to split it. However, I want to split it with a 80/20 proportion -- randomized, if possible. I know that something like : awk '{print $0 ""> "file" NR}' RS='' input-file will work, but it only... (6 Replies)
Discussion started by: owwow14
6 Replies

2. Shell Programming and Scripting

Incrementing parts of ten digits number by parts

I have number in file which contains date and serial number: 2013101000. The last two digits are serial number (00). So maximum of serial number is 100. After reaching 100 it becomes 00 with incrementing 10 which is day with max 31. after reaching 31 it becomes 00 and increments 10... (31 Replies)
Discussion started by: Natalie
31 Replies

3. Shell Programming and Scripting

Combine two parts of a file

Hello All, I have a file like this APPLY ( 'INSERT INTO brdcst_media_cntnt ( cntnt_id ,brdcst_media_cntnt_cd ,cntnt_prvdr_cd ,data_src_type_cd ,cntnt_titl_nm ,cntnt_desc ,batch_dt ,batch_id ) VALUES ( :cntnt_id (3 Replies)
Discussion started by: nnani
3 Replies

4. Shell Programming and Scripting

Extract Parts of File

Hello All, I have a file like this Define schema flat_file_schema ( a varchar(20) ,b varchar(30) ,c varchar(40) ); (Insert into table ( a ,b ,c ) values ( 1 ,2 ,3 ); (4 Replies)
Discussion started by: nnani
4 Replies

5. Shell Programming and Scripting

extract certain parts from a file

I have a logfile from which i need to extract certain pattern based on the time but the problem here is the time is not same for all days. Input file: Mon 12:34:56 abvjingjgg Mon 12:34:57 ofjhjgjhgh . . . Mon 22:30:00 kkfng . . . Mon 23:12:23 kjgsdafhkljf . . . Tue 01:04:54... (8 Replies)
Discussion started by: gpk_newbie
8 Replies

6. UNIX for Dummies Questions & Answers

How to swap parts of a file name?

I have a number of files that a structured like this: Eg. file_name.ext1 another file name with spaces.ext2 yatf with .ext3 also a file (plus).ext4 I would like to swap the part with the descriptive_file_name part, so that it looks like this: Eg. file_name .ext1 I know (or... (4 Replies)
Discussion started by: invenio
4 Replies

7. Shell Programming and Scripting

find file with space and cksum

find . -type f | xargs cksum this command is failing for the files which has a space in between them any quick solution ? preferably one liner (2 Replies)
Discussion started by: reldb
2 Replies

8. Shell Programming and Scripting

Splitting a file into unequal parts

How do I split a file into many parts but with different amounts of lines per part? I looked at the split command but that only splits evenly. I'd like a range specified to determine how many lines each output file should have. For example, if the input file has 1000 lines and the range is... (1 Reply)
Discussion started by: revax
1 Replies

9. Shell Programming and Scripting

Extracting parts of a file.

Hello, I have a XML file as below and i would like to extract all the lines between <JOB & </JOB> for every such occurance. The number of lines between them is not fixed. Anyways to do this awk? ============ <JOB APR="1" AUG="1" DEC="1" FEB="1" JAN="1" JUL="1" JUN="1" MAR="1" MAY="1"... (3 Replies)
Discussion started by: srivat79
3 Replies

10. Shell Programming and Scripting

getting parts of a file

Hello, I'm trying to retreive certain bits of info from a file. the file contains a list like this info1:info2:info3:info4 info1:info2:info3:info4 info1:info2:info3:info4 info1:info2:info3:info4 how do i pick out only info2 or only info3 without the others? Thanks (11 Replies)
Discussion started by: bebop1111116
11 Replies
Login or Register to Ask a Question