increment a value at an offset in hundreds very large hex file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting increment a value at an offset in hundreds very large hex file
# 1  
Old 06-04-2009
increment a value at an offset in hundreds of very large hex files

I have a lot of very large hex files that I need to change one value at the same offset and save to another file. I have a script that finds each file and just need to put an operator for each file.

I think sed might be able to do this but I have not used it before and would like some help. If it can't do it by offset, I believe the section before it and after it in every file, and the one value needs to be incremented.

Thanks!

-----Post Update-----

if not, is there a simple python or perl script i can write?

-----Post Update-----

if not, is there a simple python or perl script i can write?

Last edited by Eruditass; 06-04-2009 at 02:44 PM..
# 2  
Old 06-04-2009

What type of offset? Line? Byte?

What is the format of the files?
# 3  
Old 06-04-2009
Sed is not so good for editing binary files. It's not very good at arithmetic either.
# 4  
Old 06-04-2009
Quote:
Originally Posted by cfajohnson

What type of offset? Line? Byte?

What is the format of the files?
Essential to know. There is no right answer without this information.

The closest I can get to giving an answer with what little we know is that 'dd' *might* be the tool to use.
# 5  
Old 06-05-2009
its at location 0x8F. The format is hex with a semi-ASCII header.

the part that needs to be changed is in an ASCII section of the header
# 6  
Old 06-05-2009
Hex, as in, to encode the value 0x0032 it contains the literal ASCII characters 0032? Or hex as in binary, containing a binary representation of 0x32? How many bits? What endian?
# 7  
Old 06-05-2009
binary hex, little endian

i was able to sort the files to where each group had the same value to be incremented and experimented with sed, which seemed to preserve the binary fine, but will be testing it out in a program monday
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find and increment value in string of hex

I have a long string of hex (from ASN.1 data) where I need to find and change a particular hex value only and increment it. The hex pairs either side (84 and a7) of the value to increment will remain constant. i.e. "84 <length> <value_to_increment> a7" starting with 00. So end result: ... (11 Replies)
Discussion started by: securegooner
11 Replies

2. UNIX for Dummies Questions & Answers

File name offset

Dear all, I want to offset the file numbers. can you please make some awk code or linux code for the same. Example: input file names ANI_WFMASS_PIST00001.gif ANI_WFMASS_PIST00002.gif . . . ANI_WFMASS_PIST0000n.gif offset --> 30 ANI_WFMASS_PIST00031.gif ANI_WFMASS_PIST00032.gif... (14 Replies)
Discussion started by: kri321shna
14 Replies

3. UNIX for Advanced & Expert Users

Grep --byte-offset not returning the offset (Grep version 2.5.1)

Hi, I am trying to get the position of a repeated string in a line using grep -b -o "pattern" In my server I am using GNU grep version 2.14 and the code is working fine. However when I am deploying the same code in a different server which is using GNU grep version 2.5.1 the code is not... (3 Replies)
Discussion started by: Subhamoy
3 Replies

4. Shell Programming and Scripting

Get Compressed byte offset from .gz file

Hi , I have a .gz file whose contents look like below. data1^filename1 data2^filename2. .. . . Is it possible to find out the byte offset of each record from the .gz file. Like in an uncompressed file. grep -nb "Filename" give the byte offset of the record in this case. ... (4 Replies)
Discussion started by: chetan.c
4 Replies

5. Programming

What is the difference between ios::hex and std::hex?

Hi, Is there really a difference between these two, std::hex and ios::hex?? I stumbled upon reading a line, "std::ios::hex is a bitmask (8 on gcc) and works with setf(). std::hex is the operator". Is this true? Thanks (0 Replies)
Discussion started by: royalibrahim
0 Replies

6. Shell Programming and Scripting

Moving bytes in file by offset and length

Hi, I'm looking for a way (other than C) to pull out a number of bytes in a Linux file for a giving length. for example: file1 contains 2 records: abcdefghijkl mnopqrstuv ..... so, I want to pull starting in byte 9 for a length of 8 file2 would contain: ijkmnopq Thanks (2 Replies)
Discussion started by: jbt828
2 Replies

7. UNIX for Dummies Questions & Answers

adding hundreds of numbers

i know how to add two numbers using expr, but if i have a file with hundreds of numbers, how do i add them all together, without typing them all one by one? for example, file.txt contains 4 5 6 7 how can i give a command to add them, without typing $ expr `4 + 5 + 6 + 7` (7 Replies)
Discussion started by: FOBoy
7 Replies

8. Programming

After converting the hexstr to Hex and storing the Hex in a char*

Hi All, My main intension of is to convert the Hexstring stored in a char* into hex and then prefixing it with "0x" and suffix it with ',' This has to be done for all the hexstring char* is NULL. Store the result prefixed with "0x" and suffixed with ',' in another char* and pass it to... (1 Reply)
Discussion started by: rvan
1 Replies

9. UNIX for Dummies Questions & Answers

Reading a file from a specified offset

Hi, I want to read a file from a specified offset from the start of file. With the read command, is it possible to do so. Please suggest. Is there any other alternative? Thanks, Saurabh (2 Replies)
Discussion started by: saurabhsinha23
2 Replies

10. UNIX for Advanced & Expert Users

Script to Extract the line from File with specified offset

Hi All, I need to extract only XML details from large log file which may contain other unwanted junk details. For example, our xml will be start as <OUTBOUND_MESSAGE .....> and ends with </OUTBOUND_MESSAGE>. I want to extract only lines between these start and end tag (Including these tags)... (5 Replies)
Discussion started by: thinakarmani
5 Replies
Login or Register to Ask a Question