I want to extract some data from a file and save it in an array, but i don’t know how to do it.
In the following I’m extracting some data from /etc/group and save it in another file, after that I print every single item:
awk -F: '/^'$GROUP'/ { gsub(/,/,"\n",$4) ; print $4 }' /etc/group > $FILE
for i in `awk '{ print $0 }' $FILE`
do
echo "member: "$i" "
done
However, I don’t want to extract the data into a file, but into an array.
The assignment with the parentheses indicates that
$membersis an array. The originalawkcommand has been enclosed in$(...), and the colon added so that if you havegroupandgroup1in the file, and you look forgroup, you don’t get the data forgroup1too. Of course, if you wanted both entries, then you drop the colon I added.