Ask a Question related to PERL Beginners, Design and Development.
-
Randy Brown #1
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
-
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... -
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... -
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... -
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... -
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... -
Drieux #2
Re: command line search and replace
On Dec 30, 2003, at 4:51 PM, Randy Brown wrote:
you might want to revisit> 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
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
-
Drieux #3
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



Reply With Quote

