On 23/12/2010 16:28, Bauer, Bobby (NIH/CIT) [E] wrote:
OK, I'm going to forgo Rexx and learn bash script!
I want to input a file into an array. For instance I want the variable xyz to
have the contents of /tmp/test. /tmp/test looks like:
08:50:01 AM all 3.48 0.00 0.18 0.15 0.19
95.99
09:00:02 AM all 3.51 0.00 0.19 0.15 0.11
96.05
I tried:
xyz=(`cat /tmp/test`)
and
xyz=('grep all /tmp/test`)
but I only get the first word, the 08:50:01. How can I get everything?
This doesn't quite do what you think. How are you referencing the array?
$ xyz=(`cat /tmp/test`)
$ echo ${xyz[*]}
08:50:01 AM all 3.48 0.00 0.18 0.15 0.19 95.99 09:00:02 AM all 3.51 0.00
0.19 0.15 0.11 96.05
If you just ask for $xyz you get the first element of the array. Another
problem is that bash arrays are one-dimensional; you can simulate
multidimensional arrays, but why torture yourself?
http://tldp.org/LDP/abs/html/arrays.html
Perl or Python would be better suited to script processing of text files
once the requirements become anything more than simple. If you're really
keen on using bash, I'd still suggest using the "read" builtin and shell
arithmetic before resorting to arrays. Consider the memory requirements
when the input isn't 2 lines, but 2 million.
Cheers,
Phil
----------------------------------------------------------------------
For LINUX-390 subscribe / signoff / archive access instructions,
send email to lists...@vm.marist.edu with the message: INFO LINUX-390 or visit
http://www.marist.edu/htbin/wlvindex?LINUX-390
----------------------------------------------------------------------
For more information on Linux on System z, visit
http://wiki.linuxvm.org/