[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: quick scripting question - finding occurrence in many lines



On Sun, Nov 05, 2006 at 10:08:12AM -0800, Steve Lamb wrote:
> Andrew Sackville-West wrote:
> > On Mon, Nov 06, 2006 at 01:10:08AM +1100, John O'Hagan wrote:
> >> Or the whole thing could even be done with (I think!):
> 
> >> #tr -d '\n' < IN | tr ' ' '\n' | grep -B1 Processor | grep -v 'Processor\|--'
> 
> > nice.
> 
>     Except for one problem.  Look at the OP's post and you'll see that the
> word "Processor" is split by a new line.  So at no point does that word appear
> in its entirety.


tr -d '\n' 

deletes the new lines

try this

andrew@basement:~$ cat | tr -d '\n'
test<enter>
ing<enter>
<ctrl-d>
testingandrew@basement:~$ 

so that part strips all the newlines. the next tr replaces all spaces
with newlines so that each word is now on an individual line, then
grep -B1 Processor returns the line before any occurence of
Processor. not sure what the second grep does with that \-- 
in it, but I assume it is supposed to eliminate any "Processor" result
when the input includes 'Processor Processor'.

A

Attachment: signature.asc
Description: Digital signature


Reply to: