Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Awk commands in perl

Reply
Thread Tools

Awk commands in perl

 
 
rmurthy60@hotmail.com
Guest
Posts: n/a
 
      10-24-2003
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
 
Reply With Quote
 
 
 
 
Brian McCauley
Guest
Posts: n/a
 
      10-24-2003
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\\
 
Reply With Quote
 
 
 
 
Jürgen Exner
Guest
Posts: n/a
 
      10-24-2003
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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Tool for perl script to awk engineer Perl 1 06-14-2004 07:00 PM
add blank lines after word MAC (sed/awk or perl??) NNTP Perl 2 04-07-2004 06:04 AM
awk's NF in Perl Thorsten Gottschalk Perl 1 03-05-2004 08:04 PM
using perl on the command line, like sed or awk gorda Perl 2 10-21-2003 06:38 AM
sed awk or perl for this? NNTP Perl 13 09-30-2003 06:49 AM



Advertisments