Reputation: 1759
I have a tmp directory with some files in it. I need to parse these file names and then proceed to parse the contents of each one.
!/bin/bash
TMPDIR=/home/david/tmp
ip_targets(){
while IFS= read -r file_name; do
echo "This is: $file_name"
while IFS= read -r ip;do
echo "This is IP: $ip"
done < <(cat "$file_name") ## Is this wrong ?
done < <(find "$TMPDIR" -regex '.*.vms$')
}
ip_targets
How can I achieve this ? The above allows $file_name to be echoed but not the contents of it.
Upvotes: 0
Views: 96
Reputation: 39507
Try this:
!/bin/bash
TMPDIR=/home/david/tmp
ip_targets(){
while IFS= read -r file_name; do
echo "This is: $file_name"
grep -woE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b" $file_name
done < <(find "$TMPDIR" -regex '.*.vms$')
}
ip_targets
Upvotes: 1