in reply to Re^2: binary edit
in thread binary edit

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

Replies are listed 'Best First'.
Re^4: binary edit
by pbyfire (Novice) on Apr 24, 2012 at 19:30 UTC

    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