Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: binary edit

by pbyfire (Novice)
on Apr 24, 2012 at 18:23 UTC ( [id://966921]=note: print w/replies, xml ) Need Help??


in reply to Re: binary edit
in thread binary edit

Thank you for the rapid reply, unfortunately the example(s) did not work for me. It left the outfile empty. The only way I can see the string to be replaced is with a hex editor.

I am working on a *nix system and use vi all day long and I can only see the hex value and the ascii value of the string in vi calling xxd.

Replies are listed 'Best First'.
Re^3: binary edit
by dave_the_m (Monsignor) on Apr 24, 2012 at 18:43 UTC
    replace the -nle with -pe and it should work

    Dave.

Re^3: binary edit
by johngg (Canon) on Apr 24, 2012 at 19:00 UTC

    Tested using -pe rather than -nle as the -p flag does an implicit print whereas -n does not.

    knoppix@Microknoppix:~$ perl -E '$str .= chr int rand 256 for 1 .. 100 +00; print $str; substr $str, 4809, 10, q{P200000976}^C> xxxxx knoppix@Microknoppix:~$ perl -E ' > $str .= chr int rand 256 for 1 .. 10000; > substr $str, 4809, 10, q{P200000976}; > print $str;' > orig knoppix@Microknoppix:~$ hexdump -C orig | egrep '12[cd]0' 000012c0 29 72 ff 9b 1d bf 35 39 3d 50 32 30 30 30 30 30 |)rÿ..¿59= +P200000| 000012d0 39 37 36 43 4c 6d 90 9e 07 03 bb 42 32 c9 b5 ff |976CLm... +.»B2ɵÿ| knoppix@Microknoppix:~$ perl -pe 's{P200000976}{Test123456}' < orig > +modified knoppix@Microknoppix:~$ hexdump -C modified | egrep '12[cd]0' 000012c0 29 72 ff 9b 1d bf 35 39 3d 54 65 73 74 31 32 33 |)rÿ..¿59= +Test123| 000012d0 34 35 36 43 4c 6d 90 9e 07 03 bb 42 32 c9 b5 ff |456CLm... +.»B2ɵÿ| knoppix@Microknoppix:~$

    Cheers,

    JohnGG

      Thanks JohnGG that worked quite well. You were right I am trying too hard and now you know why I joined perlmonks with the username pbyfire - from bash to perl on the job makes one research more and learn faster out of necessity and you have saved me from wasting more time.

      PBYFIRE

      Oops...My apologies since Dave deserves to share in my thanks for providing the solution as well. - Thanks Dave

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://966921]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-24 20:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found