Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > using perl on the command line, like sed or awk

Reply
Thread Tools

using perl on the command line, like sed or awk

 
 
gorda
Guest
Posts: n/a
 
      10-20-2003
Hello,

Using sed or awk, I can quickly parse and perform operations on the
command line itself as in:

cat file | sed 's/cat/dog'
cat file | awk ' /cat/ {print "found the cat"} '

How can i do something like the above in perl on the command line
without having to write a script in a seperate file?

Thanks
-s
 
Reply With Quote
 
 
 
 
Steve Grazzini
Guest
Posts: n/a
 
      10-20-2003
gorda <(E-Mail Removed)> wrote:
> cat file | sed 's/cat/dog'
> cat file | awk ' /cat/ {print "found the cat"} '


Three out of five (useful uses of 'cat') ain't bad, I guess.

> How can i do something like the above in perl on the command line
> without having to write a script in a seperate file?


Have a look at the perlrun manpage.

perl -pe s/cat/dog/g file
perl -lne '/cat/ and print "found the cat"' file

--
Steve
 
Reply With Quote
 
 
 
 
Tintin
Guest
Posts: n/a
 
      10-21-2003

"gorda" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> Hello,
>
> Using sed or awk, I can quickly parse and perform operations on the
> command line itself as in:
>
> cat file | sed 's/cat/dog'
> cat file | awk ' /cat/ {print "found the cat"} '


Why the UUOC's?

sed 's/cat/dog/' file

grep -q cat file && echo "found the cat"



 
Reply With Quote
 
Barry Kimelman
Guest
Posts: n/a
 
      10-21-2003
[This followup was posted to comp.lang.perl.misc]

In article <(E-Mail Removed) >, smith4894
@excite.com says...
> Hello,
>
> Using sed or awk, I can quickly parse and perform operations on the
> command line itself as in:
>
> cat file | sed 's/cat/dog'
> cat file | awk ' /cat/ {print "found the cat"} '
>
> How can i do something like the above in perl on the command line
> without having to write a script in a seperate file?
>
> Thanks
> -s
>



perl -e "perl-command-line;"
 
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
sed/awk/perl: How to replace all spaces each with an underscore thatoccur before a specific string ? bolega Python 6 08-23-2009 12:45 AM
add blank lines after word MAC (sed/awk or perl??) NNTP Perl 2 04-07-2004 06:04 AM
regular expression for perl, tcl, sed, grep, awk Jay eL Perl Misc 2 12-09-2003 04:23 AM
using perl on the command line, like sed or awk gorda Perl 2 10-21-2003 06:38 AM
sed awk or perl for this? NNTP Perl 13 09-30-2003 06:49 AM



Advertisments