I am having a long list of IP addresses, which are not in sequence. I need to find how many IP addresses are there before/after a particular IP address. How can I achieve this?
Number of lines before and after a match, including the match (i.e. you need to subtract 1 from the result if you want to exclude the match):
sed -n '0,/pattern/p' file | wc -l sed -n '/pattern/,$p' file | wc -l
But this has nothing to do with IP addresses in particular.