Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.unix.shell > #4885
| From | "Chris F.A. Johnson" <cfajohnson@gmail.com> |
|---|---|
| Newsgroups | comp.unix.shell |
| Subject | Re: Trying to read values from a file into arrays (bash) |
| Date | 2012-05-02 20:44 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <rv0979-4bi.ln1@cjlocal.com> (permalink) |
| References | <25106263.1541.1335829369694.JavaMail.geo-discussion-forums@vbqq1> |
On 2012-04-30, deltaquattro@gmail.com wrote: > Hi, > > I'm trying to read the columns in the file foobar.fo: > > 073 1.819 > 085 2.187 > 100 2.439 > 115 2.879 > > into the array variables dir and mflow. However, I'm having some difficulties: ... > is there a way to read directly the whole > columns into dir and mflow, instead than going through a while loop? dir=( $(cut -f1 foobar.fo ) ) mflow=( $(cut -f2 foobar.fo ) ) Or, with bash4: mapfile -t dir < <(cut -f1 foobar.fo) mapfile -t mflow < <(cut -f2 foobar.fo) > Also, I'd prefer to use awk instead than cut Why? It's overkill for the job. -- Chris F.A. Johnson, author <http://shell.cfajohnson.com/> =================================================================== Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
Back to comp.unix.shell | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Trying to read values from a file into arrays (bash) deltaquattro@gmail.com - 2012-04-30 16:42 -0700
Re: Trying to read values from a file into arrays (bash) Janis Papanagnou <janis_papanagnou@hotmail.com> - 2012-05-01 08:44 +0200
Re: Trying to read values from a file into arrays (bash) deltaquattro@gmail.com - 2012-05-02 08:48 -0700
Re: Trying to read values from a file into arrays (bash) Barry Margolin <barmar@alum.mit.edu> - 2012-05-02 12:15 -0400
Re: Trying to read values from a file into arrays (bash) deltaquattro@gmail.com - 2012-05-04 01:49 -0700
Re: Trying to read values from a file into arrays (bash) Barry Margolin <barmar@alum.mit.edu> - 2012-05-04 10:12 -0400
Re: Trying to read values from a file into arrays (bash) Janis Papanagnou <janis_papanagnou@hotmail.com> - 2012-05-02 18:36 +0200
Re: Trying to read values from a file into arrays (bash) Janis Papanagnou <janis_papanagnou@hotmail.com> - 2012-05-02 18:48 +0200
Re: Trying to read values from a file into arrays (bash) deltaquattro@gmail.com - 2012-05-04 02:10 -0700
Re: Trying to read values from a file into arrays (bash) "Chris F.A. Johnson" <cfajohnson@gmail.com> - 2012-05-02 20:44 -0400
Re: Trying to read values from a file into arrays (bash) deltaquattro@gmail.com - 2012-05-04 02:05 -0700
csiph-web