Thanks for the advice. As far as using Perl or Python, I'd rather use Rexx but I'm trying to become a Linux guy instead of am MVS guy and I've got to start somewhere. Yes I know Rexx is available on Linux but for now, I choose bash for good or bad. Guess I'm familiar with arrays (or stacks as they are called in Rexx) so that's what I'll use for now. Aha!, it was my echo command that was wrong.
Bobby Bauer Center for Information Technology National Institutes of Health Bethesda, MD 20892-5628 301-594-7474 -----Original Message----- From: Philip Rowlands [mailto:linux-...@dimebar.com] Sent: Thursday, December 23, 2010 11:51 AM To: LINUX-390@VM.MARIST.EDU Subject: Re: A little more script help 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/ ---------------------------------------------------------------------- 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/