I'm trying to get this script to cat a file and grep each line for 877 and for each line found, print the first column which is an IP and store it in hosts. It get stuck on awk every time. I run sh -x some.sh to see where it is hung up. Should I print to a file instead of a list? Why does it get stuck on awk?
hosts=()
FILENAME=/home/somethin/.hosts.conf
ips=`cat $FILENAME | grep -v '877'`
for line in $ips; do
hosts=$(`awk '{print $1}'`)
done
echo $hosts
It can all be done using awk:
hosts=( $(awk '/877/{print $1}' $FILENAME) )
echo "${hosts[@]}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With