With this command I am trying to filter through my firewall. In order to extract the firewall rule ID number and the IP address.
existing=($(ufw status numbered | grep -e ''"$ssh_port"'' | grep -i 'SSH' | awk '{gsub(/[][]/,""); print $1 $5}'))
The raw output from ufw status numbered
looks like this:
[286] 22 ALLOW IN 1.1.1.1 # SSH
[287] 22 ALLOW IN 1.1.1.1 # SSH
[299] 22 ALLOW IN aaaa:aaaa:aaaa:aaaa::aaaa # SSH
What I am tying to do is return print $1 $5
as an array.
In order to access each line in bash
like this:
echo ${existing[0][0]} -> 286
echo ${existing[0][1]} -> 1.1.1.1
echo ${existing[1][0]} -> 287
echo ${existing[1][1]} -> 1.1.1.1
echo ${existing[2][0]} -> 299
echo ${existing[2][1]} -> aaaa:aaaa:aaaa:aaaa::aaaa
How can I achieve this?