sed - number of matches

This is a discussion on sed - number of matches within the shell forums in Operating Systems category; Hello again, There is another thing about sed that I could not figure out yet. I would like to know how many lines of the original file are effected by changes. I have done this so far by retrieving the line numbers of those lines that match an expression - and then counted the line numbers in C++. However, this seems to slow everything so much down, that I removed this function. But it would still be nice to know how many lines were effected. So is there a way to give sed a expression and ask for the number of ...

Go Back   Database Forum > Operating Systems > shell

Database Forums

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-26-2008, 05:24 PM
Default sed - number of matches

Hello again,

There is another thing about sed that I could not figure out yet.

I would like to know how many lines of the original file are effected
by changes. I have done this so far by retrieving the line numbers of
those lines that match an expression - and then counted the line
numbers in C++. However, this seems to slow everything so much down,
that I removed this function. But it would still be nice to know how
many lines were effected.

So is there a way to give sed a expression and ask for the number of
lines that match this expression?

Thanks for any help,

Oliver
Reply With Quote
  #2  
Old 08-26-2008, 06:13 PM
Default Re: sed - number of matches

On Tuesday 26 August 2008 22:24, Oliver Witt wrote:

> So is there a way to give sed a expression and ask for the number of
> lines that match this expression?


Sure, but it's *a lot* saner to use grep -c for that.
There are various grep ports for windows.

--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.
Reply With Quote
  #3  
Old 08-27-2008, 07:28 AM
Default Re: sed - number of matches

On Aug 26, 10:24*pm, Oliver Witt wrote:
> Hello again,
>
> There is another thing about sed that I could not figure out yet.
>
> I would like to know how many lines of the original file are effected
> by changes. I have done this so far by retrieving the line numbers of
> those lines that match an expression - and then counted the line
> numbers in C++. However, this seems to slow everything so much down,
> that I removed this function. But it would still be nice to know how
> many lines were effected.
>
> So is there a way to give sed a expression and ask for the number of
> lines that match this expression?
>
> Thanks for any help,
>
> Oliver


The wc utility can be used for counting the number of lines from the
standard output.

sed -n '/my-regexp/p' my-file | wc -l
Reply With Quote
Reply


Thread Tools
Display Modes



All times are GMT -4. The time now is 11:39 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Integrated by bbpixel2008 :: jvbPlugin R1013.368.1

Search Engine Friendly URLs by vBSEO 3.1.0
vB Ad Management by =RedTyger=
In an effort to better serve ads to our visitors, cookies are used on Mydatabasesupport.com. For more information, check out our Privacy Policy.