Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 387
  • Last Modified:

Change chars(hex) in files with a script

Hi,

can anyone help me to write a script? I want to change all chars in a file with the hex "DC" to "9A".

Thanks a lot.
0
smilidon
Asked:
smilidon
  • 2
  • 2
  • 2
1 Solution
 
jdfoxCommented:
Try this:

sed -e 's/DC/9A/g' myfile > mychangedfile

0
 
jdfoxCommented:
Oops, you did say hex characters.  It should then actually be:

sed -e 's/\xDC/\x9A/g' myfile > mychangedfile

0
 
jimbbCommented:
jdfox, which sed implementation are you using where that works?  I've tried it with GNU sed and Solaris 8 sed, and neither of them did what was expected.

smilidon, I believe this should work for you:

nawk '{gsub("\xDC", "\x9A"); print}' file

If you don't have 'nawk' then try gawk/mawk/awk or whatever you have, as long as it supports the gsub() function.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
smilidonAuthor Commented:
Hi, thanks for your help. it dont work jdfox. the hex chars are the same as before.

jimbb:
i try:

# nawk '{gsub("\xDC", "\x9A"); print}'yjvoll.htx

 Syntax Error The source line is 1.
 The error context is
                {gsub("\xDC", "\x9A"); >>>  print}yjvoll. <<< htx
 awk: 0602-500 Quitting The source line is 1.

and get this error message. Can you help please?

Thanks
0
 
smilidonAuthor Commented:
Hi, thanks for your help. it dont work jdfox. the hex chars are the same as before.

jimbb:
i try:

# nawk '{gsub("\xDC", "\x9A"); print}'yjvoll.htx

 Syntax Error The source line is 1.
 The error context is
                {gsub("\xDC", "\x9A"); >>>  print}yjvoll. <<< htx
 awk: 0602-500 Quitting The source line is 1.

and get this error message. Can you help please?

Thanks
0
 
jimbbCommented:
You are missing the space between the end of the script, and your input filename.

print}'yjvoll.htx
should be
print}' yjvoll.htx
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now