shell - Bash script, command - output to array, then print to file -
i need advice on how achieve output:
myoutputfile.txt tom hagen 1892 state: canada hank moody 1555 state: cuba j.lo 156 state: france
output of mycommand:
/usr/bin/mycommand tom hagen 1892 canada hank moody 1555 cuba j.lo 156 france
im trying achieve shell script:
ifs=$'\r\n' globignore='*' :; names=( $(/usr/bin/mycommand) ) name in ${names[@]} #echo $name echo ${name[0]} #echo ${name:0} done
thanks
assuming can rely on command output groups of 3 lines, 1 option might be
/usr/bin/mycommand | while read name; read year; read state; echo "$name $year" echo "state: $state" done
an array isn't necessary here.
one improvement exit loop if don't 3 required lines:
while read name && read year && read state; # guaranteed name, year, , state set ... done
Comments
Post a Comment