Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > substitution from command line

Reply
Thread Tools

substitution from command line

 
 
Geezer From The Freezer
Guest
Posts: n/a
 
      04-23-2004
trying to change a string in a file

perl -e s/dogshit/catshit/g filename

Seems to do nothing - what am I doing wrong?
 
Reply With Quote
 
 
 
 
BreadWithSpam@fractious.net
Guest
Posts: n/a
 
      04-23-2004
Geezer From The Freezer <(E-Mail Removed)> writes:

> perl -e s/dogshit/catshit/g filename
> Seems to do nothing - what am I doing wrong?


It's equivalent to writing a script like this:

#!/usr/bin/perl
s/dogshit/catshit/g;

and then running that script like this:

perl myscript filename

You've never actually opened filename up for reading,
nor have you looped through the contents of it, nor
printed out anything (ie. back to the file or to a
new file).

Take a look at the -n and -p (and the -i) command
line options for perl

man perlrun



--
Plain Bread alone for e-mail, thanks. The rest gets trashed.
No HTML in E-Mail! -- http://www.expita.com/nomime.html
Are you posting responses that are easy for others to follow?
http://www.greenend.org.uk/rjk/2000/06/14/quoting
 
Reply With Quote
 
 
 
 
Mothra
Guest
Posts: n/a
 
      04-23-2004
"Geezer From The Freezer" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> trying to change a string in a file
>
> perl -e s/dogshit/catshit/g filename
>
> Seems to do nothing - what am I doing wrong?


You should be running:

perl -pi -we 's/dogshit/catshit/g' filename


 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      04-23-2004
Geezer From The Freezer <(E-Mail Removed)> wrote:

> trying to change a string in a file
>
> perl -e s/dogshit/catshit/g filename

^^^^ ^^^^
^^^^ ^^^^

That was uncalled for.

It earns you a killfile entry. So long.


> Seems to do nothing - what am I doing wrong?


s/// operates on the string in $_, you do not have any string in $_.

Maybe you want to add the -p switch?


--
Tad McClellan SGML consulting
http://www.velocityreviews.com/forums/(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I pass a substitution pattern on the command line? P B Perl Misc 6 06-03-2009 03:56 PM
Command substitution in perl kp Perl Misc 5 10-09-2006 06:42 AM
Variable/multi-line substitution droman@earth.leeds.ac.uk Perl Misc 4 06-23-2005 08:41 AM
substitution fails for long line Pranav Agarwal Perl Misc 5 02-11-2004 06:24 AM
RUN/execute a Command-Line command from an ASP page. Lucas Cowald ASP .Net 4 10-23-2003 11:09 AM



Advertisments