Awk commands in perl

R

rmurthy60

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
 
B

Brian McCauley

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

Jürgen Exner

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top