Re: BASH Guru needed

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



John:

>echo ===========Loop 1==============
>declare -a RULES
>i=0
>j=4
>INFILE="/tmp/junkfile"
>RULES=(`cat $INFILE`)
>echo RULES ARRAY ${RULES[*]}

Thanks for the attempt, but the above doesn't work as expected. That was the first thing I tried early on.

Here's a working example of your suggestion and the output for anyone else interested:
#!/bin/bash

# Create a test file to read
cat >/tmp/junkfile <<-"CODE"
line 1
line 2
line 3
CODE

RRRRR=($(cat /tmp/junkfile))
echo RRRRR has ${#RRRRR[*]} elements. ${RRRRR[*]}
for ((i=0; i<${#RRRRR[*]}; ++i)); do
   echo "RRRRR[$i]=->${RRRRR[$i]}<-"
done
rm /tmp/junkfile

This splits the words per line of input as individual array elements instead of taking the line as a whole as one array element. Three lines now become six array elements because there are 6 "words". There is no way to know which array elements represent any given line and white space between words is completely gone..
i.e.
RRRRR has 6 elements. line 1 line 2 line 3
RRRRR[0]=->line<-
RRRRR[1]=->1<-
RRRRR[2]=->line<-
RRRRR[3]=->2<-
RRRRR[4]=->line<-
RRRRR[5]=->3<-



Bill Gradwohl
(817) 224-9400 x211
www.ycc.com
SPAMstomper Protected Email


-- 
Shrike-list mailing list
Shrike-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/shrike-list

[Index of Archives]     [Fedora Users]     [Centos Users]     [Kernel Development]     [Red Hat Install]     [Red Hat Watch]     [Red Hat Development]     [Red Hat Phoebe Beta]     [Yosemite Forum]     [Fedora Discussion]     [Gimp]     [Stuff]     [Yosemite News]

  Powered by Linux