using perl on the command line, like sed or awk

Discussion in 'Perl Misc' started by gorda, Oct 20, 2003.

  1. gorda

    gorda Guest

    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
    gorda, Oct 20, 2003
    #1
    1. Advertising

  2. gorda <> 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
    Steve Grazzini, Oct 20, 2003
    #2
    1. Advertising

  3. gorda

    Tintin Guest

    "gorda" <> wrote in message
    news:...
    > 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"
    Tintin, Oct 21, 2003
    #3
  4. [This followup was posted to comp.lang.perl.misc]

    In article <>, 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;"
    Barry Kimelman, Oct 21, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. NNTP

    sed awk or perl for this?

    NNTP, Sep 11, 2003, in forum: Perl
    Replies:
    13
    Views:
    3,474
    Alan Connor
    Sep 30, 2003
  2. gorda
    Replies:
    2
    Views:
    543
    Andrew Shitov
    Oct 21, 2003
  3. NNTP
    Replies:
    2
    Views:
    944
    rakesh sharma
    Apr 7, 2004
  4. hofer
    Replies:
    11
    Views:
    2,634
  5. bolega
    Replies:
    6
    Views:
    2,043
Loading...

Share This Page