Re: awk in mathematica
- To: mathgroup at smc.vnet.net
- Subject: [mg3569] Re: awk in mathematica
- From: econrad at math.ohio-state.edu (Eric Conrad)
- Date: Mon, 25 Mar 1996 21:34:21 -0500
- Organization: Department of Mathematics, The Ohio State University
- Sender: owner-wri-mathgroup at wolfram.com
In article <4itoos$v8 at dragonfly.wolfram.com>,
Luc Derrendinger <flocsim at nature.berkeley.edu> wrote:
>Dear Mathematica users
>
>Could you tell me how to use and/or implement the programming
>language AWK into mathematica ?
>Thank you for your help,
> Luc
You can prepare the awk script either ahead of time using a text editor
or during the Mathematica session using OpenWrite[], WriteString[],
and Close[]. The data file could likewise be prepared. To run awk
from within Mathematica, use the Run[] command.
Here is an example under the Unix operating system:
Script started on Fri Mar 22 10:10:03 1996
> cat foo.awk
BEGIN {print "start " FILENAME;}
$1 == "foo" {print $2;}
END {print "end " FILENAME;}
> math
Mathematica 2.2 for SPARC
Copyright 1988-94 Wolfram Research, Inc.
-- Open Look graphics initialized --
In[1]:= fp=OpenWrite["foo.data"]; WriteString[fp, "foo 1 2 3\n"];
In[2]:= WriteString[fp, "bar 4 5 6\n"]; Close[fp];
In[3]:= Run["cat foo.data"]
foo 1 2 3
bar 4 5 6
Out[3]= 0
In[4]:= Run ["awk -f foo.awk foo.data"]
start foo.data
1
end foo.data
Out[4]= 0
In[5]:= ^D
> ^D
script done on Fri Mar 22 10:12:26 1996
Good luck,
Eric
==== [MESSAGE SEPARATOR] ====