I’ve never actually had an instance where this was required, but here I am…
What I’ve (unfortunately) got is an output of netstat -nr (almost 6000 individual static routes).
I need to take that file, and eventually translate each line into a new ‘ip route add’ command once I’ve got this working.
Here’s my failcode (echos at the bottom are for testing -> I’d want to substitute them for ip route add once this works):
num=`cat $logfile | wc -l`
echo $num
echo " "
for ((i=0; i<=$num; i++))
do
dst=$(awk '{print$1}' $logfile)
gw=$(awk '{print$2}' $logfile)
mask=$(awk '{print$3}' $logfile)
echo $dst
echo $gw
echo $mask
echo " "
done
The output, instead of looking like:
Destination Gateway Netmask
looks like:
Destination Destination Destination Destination
Gateway Gateway Gateway Gateway
Netmask Netmask Netmask Netmask
How do I make it so that each time it runs, each output is a single DST/GW/netmask that I can feed into a command?
Thanks!
The answer lies in AWK:
Now replace echo with whatever command you need to run