Replacing binary data containing & using perl in HPUX 11.11

Discussion in 'Perl Misc' started by badkmail@gmail.com, Sep 23, 2008.

  1. Guest

    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.
     
    , Sep 23, 2008
    #1
    1. Advertising

  2. writes:

    > 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
     
    Peter Makholm, Sep 23, 2008
    #2
    1. Advertising

  3. writes:

    > 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--

    --
    My blog: http://shermspace.blogspot.com
    Cocoa programming in Perl: http://camelbones.sourceforge.net
     
    Sherm Pendley, Sep 23, 2008
    #3
  4. Guest

    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?
     
    , Sep 29, 2008
    #4
  5. wrote:
    > I have seen in some
    >places the constants ', & etc being used. I googled and found
    >that these are HTML constants. Is my understanding correct?


    They are called "Character entity references", please see
    http://www.w3.org/TR/html401/charset.html#entities

    >and how is it possible to use these with perl?


    You don't because Perl neither knows nor cares about them.
    To Perl those are just pieces of ordinary text.

    jue
     
    Jürgen Exner, Sep 29, 2008
    #5
  6. wrote:
    > 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;

    --
    RGB
     
    RedGrittyBrick, Sep 29, 2008
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rob Meade

    Replacing - and not Replacing...

    Rob Meade, Apr 5, 2005, in forum: ASP General
    Replies:
    5
    Views:
    299
    Chris Hohmann
    Apr 11, 2005
  2. Alex F.
    Replies:
    2
    Views:
    135
    H. Merijn Brand
    Feb 23, 2004
  3. dayo
    Replies:
    11
    Views:
    363
    Ilya Zakharevich
    Dec 16, 2005
  4. Replies:
    13
    Views:
    574
    Anno Siegel
    Sep 10, 2007
  5. Mark Hobley

    Replacing text containing parenthesis

    Mark Hobley, Apr 17, 2009, in forum: Perl Misc
    Replies:
    8
    Views:
    168
    A. Sinan Unur
    Apr 21, 2009
Loading...

Share This Page