[Thread Prev][Thread Next][Index]

Re: [ferret_users] string substitution in array



Le 2015-09-22 Andrew a écrit:
> Ferret isn't really the best tool for serious string-array processing.

Agreed.

  ...
> But in vanilla Ferret, it's often easiest to just dump the strings to
> a file, process that file with shell tools (sed, tr, cut, awk, python,
> perl, etc.), then read it back in:
> 
> yes? let a = {"a_old", "bb_old", "ccccc_old"}
> yes? list/noh/nor/clob/file="a.txt" a
> yes? sp cut -d \" -f2 a.txt | sed "s/old/new/g" > b.txt
> yes? sp rm a.txt
> yes? let b = spawn("cat b.txt")
> yes? list a,b
>              X: 0.5 to 3.5
>  Column  1: A is {"a_old", "bb_old", "ccccc_old"}
>  Column  2: B is SPAWN("cat b.txt")
>                   A       B
> 1   / 1: "a_old"     "a_new"
> 2   / 2: "bb_old"    "bb_new"
> 3   / 3: "ccccc_old" "ccccc_new"
> yes? sp rm b.txt
  ...

This works fine.  So one must choose here between playing with indices
if staying within Ferret, or using shell tools including doing some
disk I/O.

> Also note that the XSEQUENCE() in your example was redundant, since
> the {} array constructor is already x-oriented by default.

Yes, thanks.

Marco



[Thread Prev][Thread Next][Index]
Contact Us
Dept of Commerce / NOAA / OAR / PMEL / Ferret

Privacy Policy | Disclaimer | Accessibility Statement