Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

AWK and Perl on UNIX

by Zo (Scribe)
on Mar 30, 2001 at 02:23 UTC ( #68220=perlquestion: print w/replies, xml ) Need Help??

Zo has asked for the wisdom of the Perl Monks concerning the following question:

Hello all..
I'm just curious if AWK and Perl can be used simultaniously.. I mean, AWK basically (in my opinion) not very friendly, I kinda hate it, but have to use it... and my task at hand is to compare files of info using AWK. A very simple thing for me to do in Perl (done it before)... but is there a way within an AWK script to run a Perl funtion?.. and how would that be done?.. I know in AWK there's a 'SYSTEM' command.
I'm not looking for how do to my job, but is it do-able what I'm asking?.. I don't know if this sounds right, easier for me to say than to type.. cause I can talk ALOT!!! Just curious if others have done anything similar and if it's do-able, or should I just keep on trying with AWK and stay in my mode of frustration when I know that I can do this in Perl, but having hands tied here.. a slave to "da- man" at work...
in the dungeon I stay....

Replies are listed 'Best First'.
Re: AWK and Perl on UNIX
by kschwab (Vicar) on Mar 30, 2001 at 04:20 UTC
    I can't, off the top of my head, think of anything that's loads easier to do in awk instead of Perl.

    If you have some legacy awk script that you would rather not convert to perl by hand, Perl does come with an awk to perl translator. See a2p.

    As stephen said, if you give us a little info on why you need to use awk and Perl together, we might offer better advice.

      I still find that, after all these years, it's easier to write

      ls -l|awk '{print $5}'


      ls -l|perl -alne 'print $F[4]' or Newton forbid... ls -l|perl -ane 'print "$F[4]\n"'

      Not only is the awk solution clearer, it also has a lighter resource footprint.

      That is, when you string together long pipes on the command line, awk is often more compact than Perl. That's about all I use awk for these days, but I sure used to sling around a lot of data with it in the 80s.

      It's not difficult to learn to write baby awk, and if you do it will serve you well. If the job gets too tough, though (think: you can no longer run it from the command line) then it's time to switch to Perl.

      For example, user functions were retrofitted into the language, and the syntax is a bit of a botch. I can't even remember what it was now, but there was a gotcha that would rear its head up every so often and bite you.

      Just because you have a chainsaw doesn't mean you can't use a pair of secateurs.

      g r i n d e r

        I'd do that as:

        ls -l|perl -pale '$_=$F[4]'

        which saves a couple of characters. I know what you mean, but I forgot most of the awk and sed that I ever knew when I learnt Perl.


        "Perl makes the fun jobs fun
        and the boring jobs bearable" - me

Re: AWK and Perl on UNIX
by stephen (Priest) on Mar 30, 2001 at 02:58 UTC
    See system.

    Why do you need to use awk?


Re: AWK and Perl on UNIX
by Zo (Scribe) on Mar 30, 2001 at 18:42 UTC
    Thanks for the input.
    The reason why, well.. I'm at work like most people here who post problems, and there's a script that runs in a job... to extract certain info from a flatfile. Basically, I'm just modifying a current shell script. From trial and error, I've been learning AWK now... but thought that maybe others here have had to do something with AWK and have infused Perl in some way. I didn't want an answer to my specific code, just to see if others have experienced this and how they went about it.

    Thanks again and thanks in advance to anyone else who posts here.

    brother Zo

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://68220]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2019-06-17 20:53 GMT
Find Nodes?
    Voting Booth?
    Is there a future for codeless software?

    Results (80 votes). Check out past polls.

    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!