I want to monitor the number of incoming and outgoing network connections. I can get the total number with
wc -l, but I want to know how many are inbound and how many are outbound.
You can accomplish that by using ip_conntrack.
The established connections that have the source address equal to your interface's address are the outgoing connections.
The established connections that have the destination address equal to your interface's address, are the incoming connections.
(xxx.xxx.xxx.xxx is obviously your interface's ip address)
Keep in mind that there are connections that occur for inter-process communication, between applications running on your system.
You can find information about ip_conntrack entries here.
You can monitor all the incoming and outgoing connections with iftop.
If you want to get some statistics