substitution from command line

  • Thread starter Geezer From The Freezer
  • Start date
G

Geezer From The Freezer

trying to change a string in a file

perl -e s/dogshit/catshit/g filename

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

Guest

Geezer From The Freezer said:
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
 
M

Mothra

Geezer From The Freezer said:
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
 
T

Tad McClellan

Geezer From The Freezer said:
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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top