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

Re: delimiters with more than one character? ...



Hi,

Eric S Fraga wrote:
> echo " 34 + 45 \| abc \| 1 2 3 \| c\|123abc " | sed -e 's/\\|/\n/g'

I came that far too. One can wrap the result in quotation marks by adding
  | sed -e 's/^.*$/"&"/'

But how to get the lines into the array ?
I did not find much info in man bash how to do this with reasonable effort.
The mass assignment of array values seems not to respect "-quotes.

This further sequence nicely prints the index and the array element value:

  ; echo ) | \
  while read x
  do
    _S_AR[$i]="$x"
    echo $i "${_S_AR[$i]}"
    i=$(expr $i + 1)
  done

But afterwards the array elements are empty again.
The problem seems to be in the pipe before the "while".
Exporting or declaring -a _S_AR does not help.

So for now i only have this _nearly_ working:

  echo " 34 + 45 \| abc \| 1 2 3 \| c\|123abc " | sed -e 's/\\|/\n/g' >/tmp/x

  i=0
  while read x
  do
    _S_AR[$i]="$x"
    i=$(expr $i + 1)
  done </tmp/x

  rm /tmp/x

The leading and trailing blanks still get lost by "read", which for me would
be the final reason to abandon bash for the intended purpose and to begin
doing things in a programming language which gives me some more control.
(Old C programmer's wisdom:
 The last 5 percent of work in a convenience language need 95 percent of the
 project time.)


Have a nice day :)

Thomas


Reply to: