|
|
Execute command within AWK
Hi,
Is it possible for me to invoke other commands/scripts from gawk. For
example can I invoke "grep" or "wc" from within awk like
gawk '{grep ....}' file 1
"grep" and "wc" are just mentioned as an example. But the question is
about invoking commands/scripts from awk.
Thanks,
Prateek
|
|
0
|
|
|
|
Reply
|
prateek.a (24)
|
6/6/2007 7:36:14 PM |
|
Prateek wrote:
> Hi,
> Is it possible for me to invoke other commands/scripts from gawk. For
> example can I invoke "grep" or "wc" from within awk like
>
> gawk '{grep ....}' file 1
>
> "grep" and "wc" are just mentioned as an example. But the question is
> about invoking commands/scripts from awk.
>
> Thanks,
> Prateek
>
Yes:
$ awk 'BEGIN{system("echo hello")}'
hello
$ awk 'BEGIN{print "echo hello" | "/bin/sh" }'
hello
It's usually a sign that you're very confused about the best way to
design your script though....
Ed.
|
|
0
|
|
|
|
Reply
|
Ed
|
6/6/2007 7:42:18 PM
|
|
On Wed, 06 Jun 2007 12:36:14 -0700, Prateek <prateek.a@gmail.com>
wrote:
>Hi,
>Is it possible for me to invoke other commands/scripts from gawk. For
>example can I invoke "grep" or "wc" from within awk like
>
>gawk '{grep ....}' file 1
>
>"grep" and "wc" are just mentioned as an example. But the question is
>about invoking commands/scripts from awk.
>
grep is a poor example - wc is only somewhat less so because of the
large overlap in functionality.
However, wget is a good example - this is composite code from several
scripts:
WgetCommand = "wget -t 3 -T 30 -O- -U \"Mozilla/5.0
(Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219
Firefox/2.0.0.2\" http://www.wire-heads.com/istrip/ 2>"
StdErrFile = Array[ 4 ] ".response"
WgetCommand = WgetCommand StdErrFile
while( ( WgetCommand | getline ) > 0 ) {
if( !x ) {
if( match( tolower( $0 ),
/comic?[sx]?[0-9]?[\/=]([a-z0-9\-_\/]+)\./, Arr ) ) x = Arr[1]
}
(Actually, that is not working code because that test doesn't go with
that URL.)
--
T.E.D. (tdavis@gearbox.maem.umr.edu)
Remove "gearbox.maem." from address - that one is dead
|
|
0
|
|
|
|
Reply
|
Ted
|
6/6/2007 8:12:40 PM
|
|
Ed Morton wrote:
> Prateek wrote:
>> Hi,
>> Is it possible for me to invoke other commands/scripts from gawk. For
>> example can I invoke "grep" or "wc" from within awk like
>>
>> gawk '{grep ....}' file 1
>>
>> "grep" and "wc" are just mentioned as an example. But the question is
>> about invoking commands/scripts from awk.
>>
>> Thanks,
>> Prateek
>>
>
> Yes:
>
> $ awk 'BEGIN{system("echo hello")}'
> hello
> $ awk 'BEGIN{print "echo hello" | "/bin/sh" }'
> hello
>
> It's usually a sign that you're very confused about the best way to
> design your script though....
>
> Ed.
Just one note, for Prateek, not all implementations of awk have the "system"
command. Get GNU-awk.
--
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GE d+(-) s+: a@ C+ ULAHS++$ P- L+>++ E--- W++ N++ o !K w--(+) O- M?>+ V? PS+
PE+(++) Y+ PGP- t+ 5 X R !tv b+ DI(+) D G e++ h---- r+++@ y++++
------END GEEK CODE BLOCK------
|
|
0
|
|
|
|
Reply
|
SiKing
|
6/11/2007 10:07:10 AM
|
|
|
3 Replies
280 Views
(page loaded in 0.064 seconds)
Similiar Articles: Execute command within AWK - comp.lang.awkHi, Is it possible for me to invoke other commands/scripts from gawk. For example can I invoke "grep" or "wc" from within awk like gawk '{grep ....}'... AWK command inside the shell script - comp.lang.awkExecute command within AWK - comp.lang.awk Execute command within AWK - comp.lang.awk AWK command help - comp.lang.awk AWK command inside the shell script - comp.lang.awk ... Running awk from Matlab system command - comp.soft-sys.matlab ...Hi, I can run the following awk command from within Matlab (it counts the number of unique entries in column 2): system(['C:\cygwin\bin\gawk -F, '... Closing process on other side of pipe - comp.lang.awkExecute command within AWK - comp.lang.awk Closing process on other side of pipe - comp.lang.awk Hi all, I execute the following command, $ tail -f <file name> | <my_awk ... gawk/Windows/cmd.exe/ARGV - comp.lang.awkExecute command within AWK - comp.lang.awk gawk/Windows/cmd.exe/ARGV - comp.lang.awk Execute command within AWK - comp.lang.awk gawk/Windows/cmd.exe/ARGV - comp.lang.awk ... processing output of external command - comp.lang.awkExecute command within AWK - comp.lang.awk processing output of external command - comp.lang.awk... thought that by calling the "ldapsearch" command directly from awk ... exec in AWK - comp.lang.awkHow to write to file within awk ? - comp.lang.awk Execute command within AWK - comp.lang.awk Is there a simple one line command (without using foreach) to run awk on all ... awk pipe and system call - comp.lang.awkExecute command within AWK - comp.lang.awk awk pipe and system call - comp.lang.awk Execute command within AWK - comp.lang.awk Just one note, for Prateek, not all ... command line awk script summing values in column i - comp.lang.awk ...Execute command within AWK - comp.lang.awk command line awk script summing values in column i - comp.lang.awk ... Execute command within AWK - comp.lang.awk command line ... I want to run a binary from inside a ksh script - comp.unix ...AWK command inside the shell script - comp.lang.awk AWK command help - comp.lang.awk AWK command inside the shell script - comp.lang.awk I want to run a binary from ... Execute command within AWK - Application Forum at ObjectMix.comExecute command within AWK - awk . This is a discussion on Execute command within AWK - awk; Hi, Is it possible for me to invoke other commands/scripts from gawk. execute command inside awk - Der Keiler UNIX: The source for the ...Hi, below a code snippet that checks filesize and reports on this. ls -Ll /${FILE} | awk '{ if($5 < 1610612736) print $9,"Less than 1.5 Gbytes",$5 ; 7/21/2012 1:18:19 AM
|
|
|
|
|
|
|
|
|