For Programmers: Free Programming Magazines  


Home > Archive > AWK > September 2006 > How do you do this in awk?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How do you do this in awk?
casioculture@gmail.com

2006-09-01, 7:56 am



Say, for example, you have lines on which there's a - let's say -
/word\.[1-9]/

On each line there's one of these, but its location is random.

You want, not the whole line, but just that word.n printed.

Can you do that? How?

Ed Morton

2006-09-01, 7:56 am

casioculture@gmail.com wrote:
>
> Say, for example, you have lines on which there's a - let's say -
> /word\.[1-9]/
>
> On each line there's one of these, but its location is random.
>
> You want, not the whole line, but just that word.n printed.
>
> Can you do that? How?
>


function extract(str,regexp)
{ RMATCH = (match(str,regexp) ? substr(str,RSTART,RLENGTH) : "")
return RSTART
}
extract($0,"word\\.[1-9]") { print RMATCH }

Regards,

Ed.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com