From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13255 invoked from network); 22 Jan 1998 09:31:11 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 22 Jan 1998 09:31:11 -0000 Received: (from list@localhost) by math.gatech.edu (8.8.5/8.8.5) id EAA14822; Thu, 22 Jan 1998 04:24:05 -0500 (EST) Resent-Date: Thu, 22 Jan 1998 04:23:24 -0500 (EST) Sender: rz2a022@rrz.uni-hamburg.de Message-ID: <34C7105A.8331CBA4@rrz.uni-hamburg.de> Date: Thu, 22 Jan 1998 10:24:42 +0100 From: Bernd Eggink Organization: Regionales Rechenzentrum der Uni Hamburg X-Mailer: Mozilla 4.03 [en] (X11; I; Linux 2.0.30 i586) MIME-Version: 1.0 To: Sweth Chandramouli CC: zsh-users@math.gatech.edu Subject: Re: related question References: <199801150012.TAA07173@luomat.peak.org> <199801151028.KAA21473@taos.demon.co.uk> <19980121225425.23392@astaroth.nit.gwu.edu> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Resent-Message-ID: <"OBxL62.0.zc3.B0nnq"@math> Resent-From: zsh-users@math.gatech.edu X-Mailing-List: archive/latest/1247 X-Loop: zsh-users@math.gatech.edu X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu Sweth Chandramouli wrote: > > while read line ; do > for ((i=1;i<=11;i++)) ; do > field[$i]=`echo $line | cut -d';' -f$i | tr -d '"'` > done > done < in.file > > this should take a line of the format > > "foo1";"foo2";"foo3"; [...] ;"foo11" > > and stuff each foo# into the appropriate spot in the array named field. You don't need cut and tr, zsh can do all that: while read line do field=(${(s(;))line}) # split at ; field=${field#?} # remove leading quotes field=${field%?} # remove trailing quotes done > my question is, how do i then concatenate all of these values back into one > line? what i'm currently doing, since the max value for i is so small, is just > > echo > "\"$field[1]\";\"$field[2]\";\"$field[3]\";\"$field[4]\";\"$field[5]\";\"$field[ > 6]\";\"$field[7]\";\"$field[8]\";\"$field[9]\";\"$field[10]\";\"$field[11]\"" > > pretty soon, however, i'm going to have to use this script on a larger set of > data, with a lot more fields per line; i don't want to have to type out each > item of the array individually. i know there's an easier way to do it, but it's > late, and my brain isn't working very well. > > any suggestions (other than using perl, which is what all of my > coworkers say to do)? for ((i=1; i<=$#field; ++i)) do field[i]="\"$field[i]\"" # restore quotes done line=${(j(;))field} # join elements using ; Hope that helps! -- Bernd Eggink Regionales Rechenzentrum der Universitaet Hamburg eggink@rrz.uni-hamburg.de http://www.rrz.uni-hamburg.de/eggink/BEggink.html