command line search and replace

Ask a Question related to PERL Beginners, Design and Development.

  1. #1

    Default command line search and replace

    Hi all,

    When I try the following, perl reads the * as a literal character, instead of my intent as a global value. Anyone see what I am missing?

    perl -pi -e "s/<provider-url>file:*<\/provider-url>/REPLACED/g" testfile.txt


    In the file testfile.txt, the line will be something like this: <provider-url>file:/opt/usr/bin/somewhere</provider-url>

    I want to replace /opt/usr/bin/somewhere with something else, but I cannot assume what the value between <provider-url>file: and </provider-url> will be.

    Thanks for any advice.

    Randy



    -------------------------------------------------------------------------------------

    The information contained in this message is proprietary of Amdocs,

    protected from disclosure, and may be privileged.

    The information is intended to be conveyed only to the designated recipient(s)

    of the message. If the reader of this message is not the intended recipient,

    you are hereby notified that any dissemination, use, distribution or copying of

    this communication is strictly prohibited and may be unlawful.

    If you have received this communication in error, please notify us immediately

    by replying to the message and deleting it from your computer.

    Thank you.

    -------------------------------------------------------------------------------------

    Randy Brown Guest

  2. Similar Questions and Discussions

    1. Search and replace (super global replace)
      I am using the 30 day trail of acrobate professional....before I buy it I have a few questions.... 1) is there a "search and replace" function...
    2. recursive replace command line
      Hi - giving my perl a retry, I found some hints on a website to recursively replace text perl -p -i -e 's/old\(.\)atext/new\1btext/g;' $( find...
    3. RUN/execute a Command-Line command from an ASP page
      Hi, I need to RUN/execute a Command-Line command from an ASP page. This is the command: sse45.exe -i k:\o\2.wmv -o k:\o\2.shh -w 128 -df 0 -m 2...
    4. RUN/execute a Command-Line command from an ASP page.
      Hi, I need to RUN/execute a Command-Line command from an ASP page. This is the command: sse45.exe -i k:\o\2.wmv -o k:\o\2.shh -w 128 -df 0 -m 2...
    5. search replace
      Hi , How do I search replace text in a file from a perl script. i.e. by opening the file in write mode and then do a search replace. I don't...
  3. #2

    Default Re: command line search and replace


    On Dec 30, 2003, at 4:51 PM, Randy Brown wrote:
    > When I try the following, perl reads the * as a literal character,
    > instead of my intent as a global value. Anyone see what I am missing?
    >
    > perl -pi -e "s/<provider-url>file:*<\/provider-url>/REPLACED/g"
    > testfile.txt
    you might want to revisit

    perldoc perlretut

    since what you are in the midst of is a regular expression
    and it is not clear to me that you really wanted to assert

    zero or more ":"

    rather than say

    zero or more "any characters"

    which would have been

    perl -pi -e "s/<provider-url>file:.*<\/provider-url>/REPLACED/g"
    testfile.txt

    "." is the "wild card" character, which you want to have
    zero or more of, yes?


    ciao
    drieux

    ---

    Drieux Guest

  4. #3

    Default Re: command line search and replace


    On Dec 31, 2003, at 8:22 AM, Randy Brown wrote:
    > Ah yes, now the real stumper:
    >
    > The line:
    > perl -pi -e 's/<provider-url>file:.*<\/provider-url>/REPLACED/'
    > testfile.txt
    > does in fact work fine from the commandline in unix.
    >
    > However, when it is called from a ksh script, it does not function.
    > Any ideas? I have tried many possible combinations that I can think of.
    [..]

    Well the obvious part of the problem is

    how married are you to the ksh script?

    The problem you are going to be running into
    in these issues remains

    "who did which interpolation when,
    and where to what?"

    As well as which is the real problem that
    you are bumping your head into.

    Allow me to illustrate:

    meatbop: 60:] ./smack.ksh
    ../smack.ksh: Command not found.
    meatbop: 61:] which ksh
    ksh: Command not found.
    meatbop: 66:]

    vladimir: 55:] ./smack*
    vladimir: 56:] cat *.ksh
    #!/bin/ksh

    perl -pi -e 's/<provider-url>file:.*<\/provider-url>/REPLACED/'
    testfile.txt

    vladimir: 57:] cat *.txt
    REPLACED
    vladimir: 58:]

    Is the problem that you do not have ksh on the
    machine that you tried to run the perl in the ksh script?

    since that smack.ksh has no problem running the command
    and doing the dance on a host where there is both perl and ksh.

    ciao
    drieux

    Drieux Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139