spacing question

hi ,
i have follwing strings in a text file

hello i am cool
hey i am cool
arrey i am cool

in all the above 3 i wanna retrieve cool.......for this i used

split(/ /)
but it takes into consideration only one space.......is there any regular expression to do the trcik?

THANKS

regards
vivek.s

yes

$ more mr_cool
hello i am cool
hey i am cool
here is cool in the middle of a line
cool is at the beginning here...
$ sed 's/^.*\(cool\).*$/\1/g' mr_cool
cool
cool
cool
cool

Cheers
ZB

that was terrific yaar!i am awed by power unix and shell programmers :slight_smile:

but i wanted to do this in perl...sorry for not mentioning......

THANKS FOR UR KIND HELP

EDIT : SORRY I GUESS I CAN USE SED IN PERL TOO :slight_smile:

ZAZZY WHEN U FIND TIME CUD U EXPLAIN THAT REGULAR EXPRESSION OF URS?

regards
vivek.s

$ perl -p -e "s/^.*(cool).*$/\1/" mr_cool
cool
cool
cool
cool

Add -i if it does what you want

Cheers
ZB

thank you very much

EDIT : WOULD THAT WORK IN PERL PROGRAM, I REMEMBER THAT, INLINE STRINGS WOULD NOT WORK IN A PROGRAM........

regards
vivek.s

s/^.*(cool).*$/\1/

s/ - substitute
^ - beginning of line
.* - any number of anything
(cool) - if we find cool, remember that we find it - same as \(cool\) in sed
.* - any number of anything again
$ - end of line
/\1/ - replace the whole line with whatever we remembered

This is very "conceptual" - read a good regex book for more - you can have multiple \( \) and then shuffle the order of things about, e.g.

$ echo "three words here" | sed 's/^\([^ ]*\) \([^ ]*\) \([^ ]*\)/\2 \3 \1/'
words here three

Again, a full regular expression tutorial is beyond the scope of any thread... Google will be your friend here...

Cheers
ZB

Together with this thread, and your earlier thread on inline edits, you'll be able to solve this problem.

ZB

THANKS FOR HELP BOB.....I am bit more clear than i was b4!!anyway it wud take some time to comprehend the expression u gave!!:-)i wud search google for more info!!

I'll make use of both threads and solve :slight_smile:

THANK YOU

REGARDS
VIVEK>S