Although this "solution" may be off-topic, but, AFAIK, this is the most compact one there is...
That's a typical job for sed, not grep (which as we know, can't count;-): sed -e '/some.*some/d;/some/p;d' input Regards, Pjotr On Thu, Feb 14, 2008 at 10:53:30AM -0700, Steve Wampler wrote: > > A colleague was trying to get grep to do the following > (paraphrased): > > output all input rows that contain exactly one occurrence > of a given substring. > > For example, given the input: > --------------------------------------------------------- > print the line > "I want all lines that only have the word 'some' once" > don't print > "'some' lines contain the word 'some' more than once I don't care about > them" > --------------------------------------------------------- > > The output when the specified substring is 'some' should be the single line: > --------------------------------------------------------- > "I want all lines that only have the word 'some' once" > --------------------------------------------------------- > > This is hard to do with grep, but easy with Icon/Unicon > (and other languages, but that's not the topic here :) ) > > If you have some free time, you might think of solutions. > I'll be happy receive any you have. You can email them > directly to me to avoid flooding this list... I'll put > them on a TWiki page if there's any interest. This should > only be a few lines of code, so it's more of a personal > puzzle to work on instead of a programming 'challenge'. > > -- > Steve Wampler -- [EMAIL PROTECTED] > The gods that smiled on your birth are now laughing out loud. > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > Unicon-group mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/unicon-group > ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Unicon-group mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/unicon-group
