Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   Awk commands in perl (http://www.velocityreviews.com/forums/t883268-awk-commands-in-perl.html)

rmurthy60@hotmail.com 10-24-2003 05:08 PM

Awk commands in perl
 
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

Brian McCauley 10-24-2003 05:31 PM

Re: Awk commands in perl
 
rmurthy60@hotmail.com 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\\

Jürgen Exner 10-24-2003 05:37 PM

Re: Awk commands in perl
 
rmurthy60@hotmail.com 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




All times are GMT. The time now is 01:11 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.