Re: quick scripting question - finding occurrence in many lines
On Monday 06 November 2006 02:53, 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.
>
I just can't let this go! Here's a two-liner in python:
for i in open('IN').read().replace('\n', '').split('Processor')[0:-1]:
print i.split()[-1]
This creates a list of the strings delimited by each occurrence of "Processor"
(except the trailing one), then makes each string into a list of which the
last element (our number) is printed.
Regards,
john
Reply to: