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

Re: quick scripting question - finding occurrence in many lines



On Sunday 05 November 2006 17:21, John O'Hagan wrote:
> On Sunday 05 November 2006 16:42, John O'Hagan wrote:
> > On Sunday 05 November 2006 09:03, Ken Irving wrote:
> > > On Fri, Nov 03, 2006 at 09:56:12PM -0500, Douglas Tutty wrote:
> > > > On Fri, Nov 03, 2006 at 08:27:42PM +0000, michael wrote:
> >
> > [...]
> >
> > > > > eg for
> > > > >
> > > > > junk info 18 Pro
> > > > > cessor
> > > > >
> > > > > I wish to get the field '18'
[...]
>
> #!/bin/bash
>
> for newword in $(sed s/\\n//g < IN); do
>
> 	[[ $newword == "Processor" ]] && echo $oldword
> 	oldword=$newword
>
> done
>
> -------------------------


[...]

Oops, the above use of sed does not work; but it can be replaced by 

#tr -d '\n' < IN

Or the whole thing could even be done with (I think!):

#tr -d '\n' < IN | tr ' ' '\n' | grep -B1 Processor | grep -v 'Processor\|--'

i.e., remove the newlines, replace all the spaces with newlines, then grep for 
the line before "Processor".
 

Regards,

John



Reply to: