On Mon, Nov 06, 2006 at 11:27:58AM +1100, John O'Hagan wrote: > On Monday 06 November 2006 05:14, Andrew Sackville-West wrote: > > 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\|--' > > [...] > > > > > 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'. > > > > The first grep -B1 returns two lines per result, "Processor" and the number > we > are after; also, grep -B separates each result with a "--". The second > grep -v is just to remove the unwanted lines. > > E.g., if IN contains: > > junk info 18 Pro
But what if that line were: junk info 18 Pro- which seems more likely? > cessor > ggjgh 34 > Processor dgjhj > 19 Processor yytyr > fee 45 Processor tt 5 > 6 Proce > ssor rgrge > > Then (after the newline business) grep -B1 Processor gives: > > 18 > Processor > -- > 34 > Processor > -- > 19 > Processor > -- > 45 > Processor > -- > 56 > Processor > > Grep -v 'Processor\|--' gives just the numbers we want. > > Regards, > > John > > > -- > To UNSUBSCRIBE, email to [EMAIL PROTECTED] > with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED] > -- David Jardine "Running Debian GNU/Linux and loving every minute of it." -L. von Sacher-M.(1835-1895) -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]