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

[ale] OT: Bash Question



Sorry about the OT, but I didn't know where else to turn.

   I'm writing a simple shell script that cats a file to a
variable (the file is just a list). I want to loop over only
HALF of that list. So I want something like this:

NODES=$(cat node.txt)

for i in ${NODES}/2
do
   echo ${i}
done

Of course, this doesn't work.
   I've also tried "counting" the number of items in the
list, dividing by 2, and using a while loop. The only thing
is, I don't know how to access a particular element in
the list,

NODE_FILE="node.txt"
NODES=$(cat node.txt)

declare -i NP
declare -i NP2
NP=`wc -l $NODES | awk '{print $1}'`
NP2=NP/2

iloop=1
while (( $iloop <= ${NP2} ))
do
    # Here I want to echo the "iloop" element of $NODES
    let iloop+=1
done


   I really appreciate any help anyone can give. I'm also
pretty tolerant of comments about my scripting capabilities :)

Thanks!

Jeff Layton



---
This message has been sent through the ALE general discussion list.
See http://www.ale.org/mailing-lists.shtml for more info. Problems should be 
sent to listmaster at ale dot org.