[Thread Prev][Thread Next][Index]

Re: [ferret_users] spawn command gawk string arrays

Hi -
Actually it looks like it's the $2 that's tripping up the Ferret parser.

Andrew Wittenberg wrote:
Hi Patrick,

You can use the functional form of SPAWN():

yes? let a = spawn("echo Hello ferreters | awk '{print $2}'")
yes? list a
             VARIABLE : SPAWN("echo Hello ferreters | awk '{print $2}'")
             X        : 1

The list form (with {braces}) of your command seems to be choking on the
braces embedded within the awk command, which are of course almost always
required for awk.  (Ansley, is there some way to escape these?)


On Wed, 24 Mar 2010, Brockmann Patrick wrote:

I agree that some of string processing can be done with ferret string functions but gawk
provides much more than this.

My example was trying to explain how a "unclosed quotation, parenthesis, or bracket" makes impossible a use of gawk within a spawn command to define a string array.

I think that is nice when softwares have a "permeability zone" and for instance
system commands calls can be done.
It is too bad to let all gawk features gone because of a parsing problem.


I guess that like Ned, I'd use Ferret's string handling functions to process the string, rather than a call to awk.

  let instring = {spawn:"echo Hello ferreters"}
  let ns = STRINDEX (instring, " ")
  let a = SUBSTRING(instring, `ns+1`, `strlen(instring)`)

The string functions are listed here,

Brockmann Patrick wrote:
Hi all,

Is there a simple way to use gawk through the spawn command and get the result in string array ?


in shell
$ echo Hello ferreters |  awk '{print $2}'

in ferret
yes? spawn echo Hello ferreters | awk '{print $2}'

But how to get the result in a string array like

yes? LET a = {spawn:"ls *.nc"}
yes? LIST a

yes? let A = {spawn:"echo Hello ferreters | awk '{print $2}'"}
**ERROR: command syntax: {spawn:"echo Hello ferreters | awk '{print $2}'"}
         unclosed quotation, parenthesis, or bracket

Up to now, I have used a trick by passing by an external shell script like:
let A = {spawn:"echo Hello ferreters | awk -f get_2nd.awk"}

but that is not as easy as it could be.
Could the syntax parsing of the spawn command be changed ?


Data Analysis and Visualization Engineer
IPSL Global Climate Modelling Group
mailto:Patrick.Brockmann@xxxxxx --> LSCE (Orme des merisiers 712, Bureau 11)

[Thread Prev][Thread Next][Index]

Contact Us
Dept of Commerce / NOAA / OAR / PMEL / TMAP

Privacy Policy | Disclaimer | Accessibility Statement