[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: split(): syntax error near unexpected token `(' ... [OT]



Please note - this has *nothing* to do with Debian, I've marked it OT
accordingly.

Unless you are asking about Debian peculiarities or whether to raise bug
report please consider posting these sorts of queries to somewhere
appropriate like stackoverflow, gawk lists or such like. Thanks.


On 29/11/13 13:58, Albretch Mueller wrote:
>> What is "array" supposed to do?  [??]

The point of a question is to elicit an answer.

> 
>> What did you want the script to do?
> ~
>  chemie.fu-berlin.de/chemnet/use/info/gawk/gawk_13.html#SEC126


Huh? :/

A. That link is broken
B. What has gawk go to do with the script you posted?
C. In the original post you mentioned awk - and, yet, awk is not used in
your script either.  :/

gawk != split (though gawk will certainly split, as will perl).

> ~
> split(string, array [, fieldsep])

?
man split

split [OPTION]... [INPUT [PREFIX]]

split expects "cul-de-sac" to be file.


>     This divides string into pieces separated by fieldsep, and stores
> the pieces in array. The first piece is stored in array[1], the second
> piece in array[2], and so forth. The string value of the third
> argument, fieldsep, is a regexp describing where to split string (much
> as FS can be a regexp describing where to split input records). If the
> fieldsep is omitted, the value of FS is used. split returns the number
> of elements created. The split function splits strings into pieces in
> a manner similar to the way input lines are split into fields. For
> example:
> 
>     split("cul-de-sac", a, "-")

That won't work


> 
>     splits the string `cul-de-sac' into three fields using `-' as the
> separator. It sets the contents of the array a as follows:
> 
>     a[1] = "cul"
>     a[2] = "de"
>     a[3] = "sac"

No, try it.



Dunno where you keep getting gawk from. Or awk



Try this:-

#!/bin/bash
# call me ~/splitter.sh and chmod +x me
b=$1
c=$2
for stuff in ${b//$c/ } ; do
  echo $stuff
done


e.g. use:-
scott@vbserver:~$ ~/splitter.sh cul-de-sac -
cul
de
sac



HTH

Kind regards


Reply to: