Re: quick scripting question - finding occurrence in many lines

2006-11-30 Thread michael
On Wed, 2006-11-29 at 09:36 -0900, Ken Irving wrote: On Wed, Nov 29, 2006 at 02:32:37PM +, michael wrote: I guess a complete rephrase is best. What I want is how many processors does each WAITING job in lsf queues require?. From 'bhist' I get outputs such as below (see whitespace

Re: quick scripting question - finding occurrence in many lines

2006-11-30 Thread Douglas Tutty
Having all that whitespace in the 'wrong' spot breaks the idea of splitting words based on their being surrounded by whitespace. So get rid of __all__ whitespace. Then use other logic find what you want. E.g. if you want the 'word' following the 'word' processor, find the first occurance of

Re: quick scripting question - finding occurrence in many lines

2006-11-29 Thread michael
On Mon, 2006-11-06 at 01:10 +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\|--' i.e., remove the newlines, replace all the spaces with newlines, then grep for the line before

Re: quick scripting question - finding occurrence in many lines

2006-11-29 Thread michael
I guess a complete rephrase is best. What I want is how many processors does each WAITING job in lsf queues require?. From 'bhist' I get outputs such as below (see whitespace anywhere in num Processors) and cannot determine a sure way of always parsing it... Thanks, Michael EXAMPLES: ~/bin$

Re: quick scripting question - finding occurrence in many lines

2006-11-29 Thread Ken Irving
On Wed, Nov 29, 2006 at 02:32:37PM +, michael wrote: I guess a complete rephrase is best. What I want is how many processors does each WAITING job in lsf queues require?. From 'bhist' I get outputs such as below (see whitespace anywhere in num Processors) and cannot determine a sure way

Re: quick scripting question - finding occurrence in many lines

2006-11-08 Thread John O'Hagan
On Wednesday 08 November 2006 03:08, Andrew Sackville-West wrote: On Wed, Nov 08, 2006 at 02:51:20AM +1100, John O'Hagan wrote: I tried this, and found that replacing the newlines with spaces stops the grep from working because it puts spaces in the middle of any occurrences of Processor,

Re: quick scripting question - finding occurrence in many lines

2006-11-08 Thread Andrew Sackville-West
On Thu, Nov 09, 2006 at 12:52:57AM +1100, John O'Hagan wrote: tr -d '-\n' IN | tr '\n' ' ' | tr -s ' ' '\n' | grep -B1 'Processor' | grep -v 'Processor\|--' [...] Aha! You're right, my lines fail on the edge cases, and also when the target word is hyphenated. Your ingenious

Re: quick scripting question - finding occurrence in many lines

2006-11-08 Thread John O'Hagan
On Thursday 09 November 2006 03:40, Andrew Sackville-West wrote: On Thu, Nov 09, 2006 at 12:52:57AM +1100, John O'Hagan wrote: [...] while read i ; do if [[ $(echo $i | grep \\-\$ ) ]]; then i=$( echo $i | sed s/-\$//) echo $i

Re: quick scripting question - finding occurrence in many lines

2006-11-08 Thread Steve Lamb
John O'Hagan wrote: On Thursday 09 November 2006 03:40, Andrew Sackville-West wrote: SO I wonder what happened to the OP? Is he just watching waiting for the right solution, or is he long gone? [...] OP? What OP? :) The one who hopefully got an A for his answer. -- Steve C.

Re: elegance vs. one-lineness (Was: quick scripting question - finding occurrence in many lines)

2006-11-07 Thread Douglas Tutty
On Mon, Nov 06, 2006 at 10:26:53PM -0600, Russell L. Harris wrote: Andrew Sackville-West wrote: On Mon, Nov 06, 2006 at 01:34:30PM -0800, Steve Lamb wrote: Depends on what you define as elegant. when I was learning to program (mid 80's), we considered anything outside of brute force to

Re: quick scripting question - finding occurrence in many lines

2006-11-07 Thread John O'Hagan
On Tuesday 07 November 2006 02:55, Andrew Sackville-West wrote: On Tue, Nov 07, 2006 at 01:00:34AM +1100, John O'Hagan wrote: [...] You're right; but the OP, Michael, gave the above scenario as his problem. If your situation were the case, though, I guess we could use tr -d '-' to get rid

Re: elegance vs. one-lineness (Was: quick scripting question - finding occurrence in many lines)

2006-11-07 Thread Andrew Sackville-West
On Tue, Nov 07, 2006 at 08:56:55AM -0500, Douglas Tutty wrote: On Mon, Nov 06, 2006 at 10:26:53PM -0600, Russell L. Harris wrote: Andrew Sackville-West wrote: On Mon, Nov 06, 2006 at 01:34:30PM -0800, Steve Lamb wrote: Depends on what you define as elegant. when I was learning to

Re: quick scripting question - finding occurrence in many lines

2006-11-07 Thread Andrew Sackville-West
On Wed, Nov 08, 2006 at 02:51:20AM +1100, John O'Hagan wrote: I tried this, and found that replacing the newlines with spaces stops the grep from working because it puts spaces in the middle of any occurrences of Processor, but I see what you mean about the edge case. I think this

Re: quick scripting question - finding occurrence in many lines

2006-11-07 Thread Ken Irving
On Tue, Nov 07, 2006 at 08:08:12AM -0800, Andrew Sackville-West wrote: On Wed, Nov 08, 2006 at 02:51:20AM +1100, John O'Hagan wrote: ... Have we done this to death yet? :) there must be more. I haven't seen any perl junkies provide us with some permutation of

Re: quick scripting question - finding occurrence in many lines

2006-11-07 Thread Andrew Sackville-West
On Tue, Nov 07, 2006 at 09:36:27AM -0900, Ken Irving wrote: On Tue, Nov 07, 2006 at 08:08:12AM -0800, Andrew Sackville-West wrote: On Wed, Nov 08, 2006 at 02:51:20AM +1100, John O'Hagan wrote: ... Have we done this to death yet? :) there must be more. I haven't seen any perl

Re: quick scripting question - finding occurrence in many lines

2006-11-06 Thread John O'Hagan
On Monday 06 November 2006 18:38, David Jardine wrote: On Mon, Nov 06, 2006 at 11:27:58AM +1100, John O'Hagan wrote: [...] E.g., if IN contains: junk info 18 Pro But what if that line were: junk info 18 Pro- which seems more likely? [...] You're right; but the OP, Michael, gave

Re: quick scripting question - finding occurrence in many lines

2006-11-06 Thread Andrew Sackville-West
On Tue, Nov 07, 2006 at 01:00:34AM +1100, John O'Hagan wrote: On Monday 06 November 2006 18:38, David Jardine wrote: On Mon, Nov 06, 2006 at 11:27:58AM +1100, John O'Hagan wrote: [...] E.g., if IN contains: junk info 18 Pro But what if that line were: junk info 18 Pro-

Re: quick scripting question - finding occurrence in many lines

2006-11-06 Thread Paul E Condon
On Tue, Nov 07, 2006 at 01:00:34AM +1100, John O'Hagan wrote: On Monday 06 November 2006 18:38, David Jardine wrote: On Mon, Nov 06, 2006 at 11:27:58AM +1100, John O'Hagan wrote: [...] E.g., if IN contains: junk info 18 Pro But what if that line were: junk info 18 Pro-

Re: quick scripting question - finding occurrence in many lines

2006-11-06 Thread Ken Irving
On Mon, Nov 06, 2006 at 07:55:02AM -0800, Andrew Sackville-West wrote: On Tue, Nov 07, 2006 at 01:00:34AM +1100, John O'Hagan wrote: On Monday 06 November 2006 18:38, David Jardine wrote: On Mon, Nov 06, 2006 at 11:27:58AM +1100, John O'Hagan wrote: [...] E.g., if IN contains:

Re: quick scripting question - finding occurrence in many lines

2006-11-06 Thread Douglas Tutty
On Sun, Nov 05, 2006 at 05:21:23PM +1100, 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 +, michael wrote:

elegance vs. one-lineness (Was: quick scripting question - finding occurrence in many lines)

2006-11-06 Thread Steve Lamb
Douglas Tutty wrote: After thinking about it, yes it can all go in one line. Its more elegant and doesn't use up memory space but its harder to read to understand what its doing. Depends on what you define as elegant. I dropped Perl several years ago in preference to Python because I

Re: quick scripting question - finding occurrence in many lines

2006-11-06 Thread Douglas Tutty
With all the permutations, especially around possible hyphenations, it starts to be easier to look at whatever is creating this hypothetical silly hyphenated file. (note its the file thats silly, not the hypothetical suggestion of hyphens). Sometimes its too easy to keep trying to solve the

Re: quick scripting question - finding occurrence in many lines

2006-11-06 Thread Steve Lamb
Douglas Tutty wrote: Sometimes its too easy to keep trying to solve the wrong problem. True, but it sure does answer the question How do you keep a programmer geek busy? :) -- Steve C. Lamb | But who decides what they dream? PGP Key: 8B6E99C5 | And dream I

Re: elegance vs. one-lineness (Was: quick scripting question - finding occurrence in many lines)

2006-11-06 Thread Andrew Sackville-West
On Mon, Nov 06, 2006 at 01:34:30PM -0800, Steve Lamb wrote: Depends on what you define as elegant. when I was learning to program (mid 80's), we considered anything outside of brute force to be elegant. Also, anything non-obvious was also considered elegant. Anything that used a

Re: quick scripting question - finding occurrence in many lines

2006-11-06 Thread Douglas Tutty
On Mon, Nov 06, 2006 at 04:58:18PM -0800, Steve Lamb wrote: Douglas Tutty wrote: Sometimes its too easy to keep trying to solve the wrong problem. True, but it sure does answer the question How do you keep a programmer geek busy? :) If you want to keep busy, write this in assembler

Re: elegance vs. one-lineness (Was: quick scripting question - finding occurrence in many lines)

2006-11-06 Thread Russell L. Harris
Andrew Sackville-West wrote: On Mon, Nov 06, 2006 at 01:34:30PM -0800, Steve Lamb wrote: Depends on what you define as elegant. when I was learning to program (mid 80's), we considered anything outside of brute force to be elegant. Also, anything non-obvious was also considered

Re: quick scripting question - finding occurrence in many lines

2006-11-05 Thread John O'Hagan
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 +, michael wrote:

Re: quick scripting question - finding occurrence in many lines

2006-11-05 Thread Andrew Sackville-West
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. A signature.asc Description: Digital signature

Re: quick scripting question - finding occurrence in many lines

2006-11-05 Thread Steve Lamb
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

Re: quick scripting question - finding occurrence in many lines

2006-11-05 Thread Andrew Sackville-West
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\|--'

Re: quick scripting question - finding occurrence in many lines

2006-11-05 Thread Steve Lamb
Andrew Sackville-West wrote: tr -d '\n' deletes the new lines Ahhh, ok. Was still going off of the previous Python examples which didn't delete newlines, only replaced them with spaces. Mea Culpa. -- Steve C. Lamb | But who decides what they dream? PGP Key:

Re: quick scripting question - finding occurrence in many lines

2006-11-05 Thread Andrew Sackville-West
On Sun, Nov 05, 2006 at 10:29:42AM -0800, Steve Lamb wrote: Andrew Sackville-West wrote: tr -d '\n' deletes the new lines Ahhh, ok. Was still going off of the previous Python examples which didn't delete newlines, only replaced them with spaces. Mea Culpa. I have to say that

Re: quick scripting question - finding occurrence in many lines

2006-11-05 Thread John O'Hagan
On Monday 06 November 2006 05:29, Steve Lamb wrote: Andrew Sackville-West wrote: tr -d '\n' deletes the new lines Ahhh, ok. Was still going off of the previous Python examples which didn't delete newlines, only replaced them with spaces. Mea Culpa. Oops again! What I meant to do

Re: quick scripting question - finding occurrence in many lines

2006-11-05 Thread John O'Hagan
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'

Re: quick scripting question - finding occurrence in many lines

2006-11-05 Thread John O'Hagan
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

Re: quick scripting question - finding occurrence in many lines

2006-11-05 Thread David Jardine
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

Re: quick scripting question - finding occurrence in many lines

2006-11-04 Thread David Clymer
On Fri, 2006-11-03 at 13:32 -0800, Aleksei Dzhulai wrote: The simplest case: awk '{for (i=1;i=NF;i++) {if ($i~/Processor/) print $(i-1)} }' file This doesn't work at all for me. Given the file: BOF junk info 18 Pro cessor EOF It produces no output. I think this should do what you want.

Re: quick scripting question - finding occurrence in many lines

2006-11-04 Thread Ken Irving
On Fri, Nov 03, 2006 at 09:56:12PM -0500, Douglas Tutty wrote: On Fri, Nov 03, 2006 at 08:27:42PM +, michael wrote: I've been trying to do this with 'awk' but am hitting probs (not used awk for ages!) so all offers welcome! Given a multiple line file, IN, that contains the word

Re: quick scripting question - finding occurrence in many lines

2006-11-04 Thread Ken Irving
On Sat, Nov 04, 2006 at 01:03:14PM -0900, 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 +, michael wrote: I've been trying to do this with 'awk' but am hitting probs (not used awk for ages!) so all offers welcome!

Re: quick scripting question - finding occurrence in many lines

2006-11-04 Thread John O'Hagan
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 +, michael wrote: [...] eg for junk info 18 Pro cessor I wish to get the field '18' [...] Since it appears that

Re: quick scripting question - finding occurrence in many lines

2006-11-04 Thread John O'Hagan
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 +, michael wrote: [...] eg for junk info 18 Pro cessor I

quick scripting question - finding occurrence in many lines

2006-11-03 Thread michael
I've been trying to do this with 'awk' but am hitting probs (not used awk for ages!) so all offers welcome! Given a multiple line file, IN, that contains the word Processor (possibly split over 2 lines) I wish to output the field immediately preceeding Processor. eg for junk info 18 Pro cessor

Re: quick scripting question - finding occurrence in many lines

2006-11-03 Thread Ken Irving
On Fri, Nov 03, 2006 at 08:27:42PM +, michael wrote: I've been trying to do this with 'awk' but am hitting probs (not used awk for ages!) so all offers welcome! Given a multiple line file, IN, that contains the word Processor (possibly split over 2 lines) I wish to output the field

Re: quick scripting question - finding occurrence in many lines

2006-11-03 Thread Aleksei Dzhulai
The simplest case: awk '{for (i=1;i=NF;i++) {if ($i~/Processor/) print $(i-1)} }' file michael писал(а): I've been trying to do this with 'awk' but am hitting probs (not used awk for ages!) so all offers welcome! Given a multiple line file, IN, that contains the word Processor (possibly

Re: quick scripting question - finding occurrence in many lines

2006-11-03 Thread michael
On Fri, 2006-11-03 at 13:32 -0800, Aleksei Dzhulai wrote: The simplest case: awk '{for (i=1;i=NF;i++) {if ($i~/Processor/) print $(i-1)} }' file I don't think that will pick up the case where the required output is on the line before Processor, but thanks, M -- To UNSUBSCRIBE, email to

Re: quick scripting question - finding occurrence in many lines

2006-11-03 Thread Bob McGowan
michael wrote: On Fri, 2006-11-03 at 13:32 -0800, Aleksei Dzhulai wrote: The simplest case: awk '{for (i=1;i=NF;i++) {if ($i~/Processor/) print $(i-1)} }' file I don't think that will pick up the case where the required output is on the line before Processor, but thanks, M I didn't catch

Re: quick scripting question - finding occurrence in many lines

2006-11-03 Thread Douglas Tutty
On Fri, Nov 03, 2006 at 08:27:42PM +, michael wrote: I've been trying to do this with 'awk' but am hitting probs (not used awk for ages!) so all offers welcome! Given a multiple line file, IN, that contains the word Processor (possibly split over 2 lines) I wish to output the field