Replacing binary data containing & using perl in HPUX 11.11

B

badkmail

Using Perl, I want to search for a binary data containing & and
alphabets and replace with another string. I am getting an error as
put below:

bash-3.2# echo fsdalf&l91Afjkdf | perl -p -e 's/l91A/l2A/g;'
[1] 11326
fsdalf
bash: l91Afjkdf: command not found
[1]+ Done echo fsdalf
bash-3.2#

My requirement is: I have a binary data which can contain any byte
from 0x00 to 0xFF. I want to search for particular set of characters,
say &A12B and replace it with another set of characters, say &A4B.

Please let me know how to do the same. Thanks in advance.
 
P

Peter Makholm

bash-3.2# echo fsdalf&l91Afjkdf | perl -p -e 's/l91A/l2A/g;'
[1] 11326
fsdalf
bash: l91Afjkdf: command not found
[1]+ Done echo fsdalf
bash-3.2#

This is not at perl issue, but you shell using the ampersand as part
of it's syntax. You'll have to quote the argument to echo:

$ echo 'fsdalf&l91Afjkdf' | perl -p -e 's/l91A/l2A/g;'
fsdalf&l2Afjkdf
$


//Makholm
 
S

Sherm Pendley

Using Perl, I want to search for a binary data containing & and
alphabets and replace with another string. I am getting an error as
put below:

bash-3.2# echo fsdalf&l91Afjkdf | perl -p -e 's/l91A/l2A/g;'
[1] 11326
fsdalf
bash: l91Afjkdf: command not found
[1]+ Done echo fsdalf
bash-3.2#

That's not a Perl error - bash is interpreting the & as the end of a
command. You need to quote shell command arguments that include things
like that:

sherm:~ sherm$ echo fsdalf&191Afjkdf | perl -p -e 's/191A/12A/g;'
[1] 11387
fsdalf
-bash: 191Afjkdf: command not found
[1]+ Done echo fsdalf

sherm:~ sherm$ echo "fsdalf&191Afjkdf" | perl -p -e 's/191A/12A/g;'
fsdalf&12Afjkdf

sherm--
 
B

badkmail

Thanks Sherm and Peter. I have another query. I have seen in some
places the constants ', & etc being used. I googled and found
that these are HTML constants. Is my understanding correct? and how is
it possible to use these with perl?
 
R

RedGrittyBrick

Thanks Sherm and Peter. I have another query. I have seen in some
places the constants ', & etc being used. I googled and found
that these are HTML constants. Is my understanding correct? and how is
it possible to use these with perl?

use HTML::Entities;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top