I'm trying to read an openvpn status log to get connected users. I've tried following the answer here, but no luck.
Here's my file:
OpenVPN CLIENT LIST
Updated,Mon Jul 13 10:53:46 2020
Common Name,Real Address,Bytes Received,Bytes Sent,Connected Since
user123,8.9.10.11:24142,143404433,5616022,Mon Jul 13 10:09:31 2020
ROUTING TABLE
Virtual Address,Common Name,Real Address,Last Ref
192.168.1.2,user123,8.9.10.11:24142,Mon Jul 13 10:53:45 2020
GLOBAL STATS
Max bcast/mcast queue length,1
END
I want the lines between "Common" and "ROUTING", e.g:
user123,8.9.10.11:24142,143455713,5682214,Mon Jul 13 10:09:31 2020
Using this:
awk '/Common/{flag=1;next}/ROUTING/{flag=0}flag' /pathtomylog/openvpn-status.log
I get:
user123,8.9.10.11:24142,143455713,5682214,Mon Jul 13 10:09:31 2020
192.168.1.2,user123,8.9.10.11:24142,Mon Jul 13 11:00:36 2020
GLOBAL STATS
Max bcast/mcast queue length,1
END
Any help appreciated.
Edit: The following code worked perfectly. The issue was the 2nd instance of Common
.
sudo awk '/ROUTING/{flag=""} /^Common/{flag=1;next} flag' Input file