[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: loop through records
From: |
Tony Zanella |
Subject: |
Re: loop through records |
Date: |
Wed, 11 Mar 2009 16:23:12 -0400 |
awk may be a help here. Using it, you can refer to fields, like so:
$ cat f1
187431346 0323 mirrored 11866
187431346 0324 mirrored 11866
187431346 0325 mirrored 11866
187431346 0326 mirrored 11866
$ awk '{print $1;print$2}' f1
187431346
0323
187431346
0324
187431346
0325
187431346
0326
On Wed, Mar 11, 2009 at 4:11 PM, OnTheEdge <duaneschweitzer@gmail.com> wrote:
>
> All, I'm trying to figure out how to loop through an array of records (if
> possible) and reference fields in that record, but I've only been able to
> reference the entire array (array[0]) or when assigned with parens, there is
> no concept of a row...
>
> #!/bin/bash
>
> array1="187431346 0323 mirrored 11866
> 187431346 0324 mirrored 11866
> 187431346 0325 mirrored 11866
> 187431346 0326 mirrored 11866"
>
> element_count1=${#array1[*]}
> echo $element_count1
>
> number_of_elements=${#array1[@]}
>
> echo '- ARRAY-1--------------------------------'
>
> for REC in "${array1[*]}"
> do
> echo "Field 1: ${REC[0]} Field 2: ${REC[1]}"
> done
>
> I would like to see something like this:
> Field 1: 187431346 Field 2: 0323
> Field 1: 187431346 Field 2: 0324
> Field 1: 187431346 Field 2: 0325
> Field 1: 187431346 Field 2: 0326
>
> Thanks....
> --
> View this message in context:
> http://www.nabble.com/loop-through-records-tp22463462p22463462.html
> Sent from the Gnu - Bash mailing list archive at Nabble.com.
>
>
>
>