Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Manipulating binary file?? 2

Status
Not open for further replies.

alqsp

Programmer
Dec 12, 2001
9
AU
I need to manipulate a binary file (just holding data) using parameters - 1) file name 2) starting position of data to change 3) new value.

Question is: Is it possible to write a unix script to do this? Is it powerful enough??

Thoughts? If not possible any alternatives?
 
Hi,
Here is one way to do it. Lets say your file is "binfile" and the position of the data to be changed is characters 856 thru 891.

dd if=binfile of=binfile.1st ibs=855 count=1 (this will produce the 1st 'piece' of the file up to the position you want to change, copying only the first 855 characters.

dd if=binfile of=binfile.last ibs=891 skip=1 (this will produce the last 'piece' of the file from the 892nd character to the end, skipping the first 891 characters.

Now you can edit or echo the new data to a middle piece, such as: echo datanew > binfile.change

Now just cat the files together:
cp binfile.1st binfile.new
cat binfile.change >> binfile.new
cat binfile.last >> binfile.new

 
That's good, thankyou.

I used: echo datanew'/c' > binfile.change - to suppress the new line character.

Now what I want to know is if datanew is just ascii, is there a way to convert it to binary or hex?


 
You would need to write your binfile.change file in the correct format, as opposed to using echo which, I think, was just used as an example here. Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top