Awk commands in perl

Discussion in 'Perl Misc' started by rmurthy60@hotmail.com, Oct 24, 2003.

  1. Guest

    How do i write awk commands in perl.

    Can i do something like this system("awk '{print $3}'"); for example
    or do i have to use qx or something else. I am not able to use any awk
    commands.

    Thanks
    Raghu
    , Oct 24, 2003
    #1
    1. Advertising

  2. writes:

    > How do i write awk commands in perl.


    a2p

    Oh, sorry that's not the question you were asking. But come to think
    of it, it probably is at least part of the answer to the question you
    _should_ have been asking.

    > Can i do something like this system("awk '{print $3}'"); for example


    Well, obviously you'd have to remember that $ is meta in perl
    double-qouted strings.

    system("awk '{print \$3}'");

    OR

    system('awk','{print $3}');

    But you could only do this if you wanted awk's STDIN and STDOUT to be
    simply connected to the current process's STDIN and STDOUT and for the
    current process to wait for the subprocess to finish.

    This is an untterly improbable thing to want to do. The again piping
    to or from the above script in Perl is an equally improbable thing to
    want to do as it's trivial to do the same in thing directly in Perl.

    > or do i have to use qx or something else.


    If you want to redirect the STDIN and/or STDOUT of a child process in
    Perl the you need something other than system(). This, of course, has
    nothing to do with awk.

    Have you considered reading the manual at all?

    > I am not able to use any awk commands.


    Why? What happens when you try? Do your hands rebel and refuse to
    type the commands? It could be that your subcouncious knows you
    should use Perl so is paralysing your hands.

    --
    \\ ( )
    . _\\__[oo
    .__/ \\ /\@
    . l___\\
    # ll l\\
    ###LL LL\\
    Brian McCauley, Oct 24, 2003
    #2
    1. Advertising

  3. wrote:
    > How do i write awk commands in perl.
    >
    > Can i do something like this system("awk '{print $3}'"); for example
    > or do i have to use qx or something else. I am not able to use any awk
    > commands.


    Sure you can, why not?
    But why not do the processing directly in Perl instead of shelling out an
    external process to awk?

    In any case, I have a certain feeling that maybe you don't understand what
    $3 is. You are stringifying the argument to system.
    Are you sure you want the third group that was matched in the last
    successfull regular expression as an argument to the print statement for
    awk? I.e. if your last successful RE was /(foo)(bar)(match)/ then your
    system command would call
    awk 'print{match}'

    If you don't want stringification, then don't use it. Use e.g. single quotes
    instead.
    For further details please see "perldoc perlop", section "Quotes and
    quotelike expressions"
    See also "perldoc -q quote": "What's wrong with always quoting "$vars"?"

    jue
    Jürgen Exner, Oct 24, 2003
    #3
    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,473
    Alan Connor
    Sep 30, 2003
  2. gorda
    Replies:
    2
    Views:
    542
    Andrew Shitov
    Oct 21, 2003
  3. Thorsten Gottschalk

    awk's NF in Perl

    Thorsten Gottschalk, Mar 5, 2004, in forum: Perl
    Replies:
    1
    Views:
    3,662
    Jim Gibson
    Mar 5, 2004
  4. NNTP
    Replies:
    2
    Views:
    943
    rakesh sharma
    Apr 7, 2004
  5. engineer

    Tool for perl script to awk

    engineer, Jun 14, 2004, in forum: Perl
    Replies:
    1
    Views:
    872
    Joe Smith
    Jun 14, 2004
Loading...

Share This Page