Count total number of lines before/after a pattern match Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Count total number of lines before/after a pattern match without wasting too much if your time.

The question is published on by Tutorial Guruji team.

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?

Answer

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.

We are here to answer your question about Count total number of lines before/after a pattern match - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji