Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Command line pipe question

Reply
Thread Tools

Command line pipe question

 
 
RyanY
Guest
Posts: n/a
 
      10-20-2005
Hello,

I am wondering if it is possible to pipe input to the -i command line
switch. For example:

perl -i -pe'orig_*' 's/string/newString/g' file1

will change all occurances of "string" with "newString" and create a
file called "orig_file1" that will be the original file. How do I pipe
the output of ls to this?

The following doesn't work.

ls *.txt|perl -i -pe'orig_*' 's/string/newString/g'

I have read the perlfaq5 and understand how to do this within a perl
script. However, I came across the -i command line switch and wanted
to know if I could just pipe the filenames to it.

Thanks,
Ryan

 
Reply With Quote
 
 
 
 
John Bokma
Guest
Posts: n/a
 
      10-20-2005
"RyanY" <(E-Mail Removed)> wrote:

> Hello,
>
> I am wondering if it is possible to pipe input to the -i command line
> switch. For example:
>
> perl -i -pe'orig_*' 's/string/newString/g' file1
>
> will change all occurances of "string" with "newString" and create a
> file called "orig_file1" that will be the original file. How do I pipe
> the output of ls to this?
>
> The following doesn't work.
>
> ls *.txt|perl -i -pe'orig_*' 's/string/newString/g'


No, because -i means edit in place, so how do you want to edit the output
of ls in place

dir | perl -pe "s/a/b/g"

works here. (BTW, I don't understand your perl -i pe'orig_*' syntax, since
to me that would run 'orig_*' as perl code)

--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
I ploink googlegroups.com

 
Reply With Quote
 
 
 
 
xhoster@gmail.com
Guest
Posts: n/a
 
      10-21-2005
"RyanY" <(E-Mail Removed)> wrote:
> Hello,
>
> I am wondering if it is possible to pipe input to the -i command line
> switch. For example:
>
> perl -i -pe'orig_*' 's/string/newString/g' file1
>
> will change all occurances of "string" with "newString" and create a
> file called "orig_file1" that will be the original file.


I'm pretty sure it won't. The argument to -i has to be immediately
after -i, with no intervening whitespace and certainly no intervening
switches.


> How do I pipe
> the output of ls to this?
>
> The following doesn't work.
>
> ls *.txt|perl -i -pe'orig_*' 's/string/newString/g'


Use the shell.

perl -i'orig_*' -pe 's/string/newString/g' `ls *.txt`

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
John W. Krahn
Guest
Posts: n/a
 
      10-21-2005
RyanY wrote:
>
> I am wondering if it is possible to pipe input to the -i command line
> switch. For example:
>
> perl -i -pe'orig_*' 's/string/newString/g' file1
>
> will change all occurances of "string" with "newString" and create a
> file called "orig_file1" that will be the original file.


No. That will run the expression 'orig_*' for every line in the two files
s/string/newString/g and file1 and edit them in-place without creating a
backup file.


> How do I pipe the output of ls to this?


You don't really want to do that.


> The following doesn't work.
>
> ls *.txt|perl -i -pe'orig_*' 's/string/newString/g'


perl -i'orig_*' -pe's/string/newString/g' *.txt



John
--
use Perl;
program
fulfillment
 
Reply With Quote
 
Tintin
Guest
Posts: n/a
 
      10-21-2005

<(E-Mail Removed)> wrote in message
news:20051020202550.828$(E-Mail Removed)...
> "RyanY" <(E-Mail Removed)> wrote:
>> Hello,
>>
>> I am wondering if it is possible to pipe input to the -i command line
>> switch. For example:
>>
>> perl -i -pe'orig_*' 's/string/newString/g' file1
>>
>> will change all occurances of "string" with "newString" and create a
>> file called "orig_file1" that will be the original file.

>
> I'm pretty sure it won't. The argument to -i has to be immediately
> after -i, with no intervening whitespace and certainly no intervening
> switches.
>
>
>> How do I pipe
>> the output of ls to this?
>>
>> The following doesn't work.
>>
>> ls *.txt|perl -i -pe'orig_*' 's/string/newString/g'

>
> Use the shell.
>
> perl -i'orig_*' -pe 's/string/newString/g' `ls *.txt`


UUOLS

perl -i'orig_*' -pe 's/string/newString/g' *.txt


 
Reply With Quote
 
xhoster@gmail.com
Guest
Posts: n/a
 
      10-21-2005
"Tintin" <(E-Mail Removed)> wrote:
> <(E-Mail Removed)> wrote in message
> news:20051020202550.828$(E-Mail Removed)...
> > "RyanY" <(E-Mail Removed)> wrote:
> >> Hello,
> >>
> >> I am wondering if it is possible to pipe input to the -i command line
> >> switch. For example:
> >>
> >> perl -i -pe'orig_*' 's/string/newString/g' file1
> >>
> >> will change all occurances of "string" with "newString" and create a
> >> file called "orig_file1" that will be the original file.

> >
> > I'm pretty sure it won't. The argument to -i has to be immediately
> > after -i, with no intervening whitespace and certainly no intervening
> > switches.
> >
> >
> >> How do I pipe
> >> the output of ls to this?
> >>
> >> The following doesn't work.
> >>
> >> ls *.txt|perl -i -pe'orig_*' 's/string/newString/g'

> >
> > Use the shell.
> >
> > perl -i'orig_*' -pe 's/string/newString/g' `ls *.txt`

>
> UUOLS
>
> perl -i'orig_*' -pe 's/string/newString/g' *.txt


I assumed the OP was following the guidelines by reducing his problem
to the simplest case that demonstrates what he wanted to demonstrate.
Doing that often results in constructs which are useless if you consider
the program to be an end-in-itself, but are not useless if you consider it
as what it is, a simplified demonstration.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
usenet@DavidFilmer.com
Guest
Posts: n/a
 
      10-21-2005
Tintin wrote:
> UUOLS


What is UUOLS?

 
Reply With Quote
 
xhoster@gmail.com
Guest
Posts: n/a
 
      10-21-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Tintin wrote:
> > UUOLS

>
> What is UUOLS?


Useless Use of ls.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
 
Reply With Quote
 
RyanY
Guest
Posts: n/a
 
      10-21-2005

(E-Mail Removed) wrote:
> (E-Mail Removed) wrote:
> > Tintin wrote:
> > > UUOLS

> >
> > What is UUOLS?

>
> Useless Use of ls.
>
> Xho
>
> --
> -------------------- http://NewsReader.Com/ --------------------
> Usenet Newsgroup Service $9.95/Month 30GB


Thanks everyone. Yes, I mistyped the original post. The 'orig-*'
should have been with the i switch.

 
Reply With Quote
 
usenet@DavidFilmer.com
Guest
Posts: n/a
 
      10-21-2005
RyanY wrote:

This is why the clpm posting guidelines recommend:
>>> Do not re-type Perl code
>>> Use copy/paste or your editor's ``import'' function rather than
>>> attempting to type in your code. If you make a typo you will get
>>> followups about your typos instead of about the question you are
>>> trying to get answered.


Good advice:
http://mail.augustmail.com/~tadmc/cl...uidelines.html

 
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
Problem: Windows Command line Pipe to stdin GerShar Python 1 10-31-2005 02:24 AM
[named pipe] i wanna know about validate of pipe handle of client lee, wonsun C++ 1 11-02-2004 04:29 AM
Need simple command for validating xml files at the command line Bernd Oninger XML 1 07-07-2004 06:20 PM
Why does IO::Pipe::END generate an EXCEPT pipe message? lvirden@gmail.com Perl Misc 1 06-02-2004 02:17 PM
RUN/execute a Command-Line command from an ASP page. Lucas Cowald ASP .Net 4 10-23-2003 11:09 AM



Advertisments