I have a little problem with commands. I know this is about shell scripting but i couldn't find a thread for commandlines. So i have this assignment to "display all the lines for tcp- services and udp- services and count the lines" and i honestly don't have an idea how to do that, i know how to count the lines tho XD...if someone could help me i would be grateful. :)
Well both of those methods are imperfect for counting connections, but you're probably getting a more accurate result with grep in this case, because it won't count the first two lines (if your output is like mine)
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
Also consider that the result may actually be different from one moment to the next.
OR I like to do things where we're getting multiple numbers from the same output, in more of a snapshot form since the numbers CAN change from one moment to the next. Something like this may be more appropriate, depending on the ultimate goal of your script: