Wednesday, May 25, 2011

modifying hex codes with a regex replace

I'm trying to modify a series of binary files made with a legacy
program, and need to change a certain character in my search string to
the character with hex code +4. For context, here is my sed regex:

:s!^@Heading level 1^@\+.\{-}^@\+\(\d\+\)^@\+Body text^@vel 1^@\+\(\_.
\{1}\)[^D^A^@]\+!^@Body text^@vel 2^@^@\2^@^@^Y#\1^Z

with HEX(^@) =00, etc. String 2 is only 1 character long, but is
occasionally rendered as a carriage return, thus the need for the \_.
\{1} pattern. Instead of writing the exact character of string 2, I
need to write the character +4 to its hex code. For instance, if
HEX(string2)=97, I would need to print ASCII(9b).

Any ideas on how to do this?

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: