Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have several binary files with the character 0x04 in them, and I'd like to add an escape \ character before each. Is there a script I can use to do this without needing to manually edit each one?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

You can use GNU sed as in the following example:

for file in /path/*; do
  sed -i 's/\x04/\\&/g' "$file"
done

Be aware that -i option modify the file in place, so be sure to have a backup, something should go wrong.

share|improve this answer
    
That's works perfectly many thanks Enzo and Michael!!! –  Luiz Aug 11 '11 at 20:00
    
@Luiz You can upvote this and accept it if it solved your problem –  Michael Mrozek Aug 11 '11 at 20:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.