parameter to perl -p -i -e s/ command from .sh script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • liveunix
    New Member
    • May 2007
    • 1

    parameter to perl -p -i -e s/ command from .sh script

    Code:
    #!/usr/bin/bash
    RUN=R1
    filename=f1
    
    perl -p -i -e 's/qq{$RUN}/\|\d\d\d\d\|[A-Z]*/R3/i' $filename
    I am expecting $RUN to be expanded by shell
    Also plz note my file f1 is like this
    R1|1000|SUCCESS
    and i am replacing it by
    R3

    Please let me know what is wrong in this?

    Thanks
  • miller
    Recognized Expert Top Contributor
    • Oct 2006
    • 1086

    #2
    I have never done bash variable interpolation like that, so I don't know the proper syntax to get it to work. Nevertheless, assuming that you can get that part to work, the regular expression that you'll want would be this:

    Code:
    perl -pie 's/R1\|\d{4}\|[A-Z]*/R3/i' $filename
    Therefore remove the qq{} enclosing $RUN, unless this is necessary for the variable to be interpolated, and also remove the / after that as well.

    - Miller

    Comment

    Working...