Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

awk pattern matching

Status
Not open for further replies.

goros

Programmer
May 15, 2011
4
GR
Hello!

In a line like this

21zCases-Peripherals Combo LOGITECH 176-83-LODMK250 LOGITECH WIRELESS DESKTOP MK250 920-002653 920-002653 ????????? 16,90 0,24 22,82

i'm trying to extract /176-83-LODMK250/ with /^[0-9]{2,3}-[0-9]{2,3}-*/)print $i

but is not working.

Some suggestions??

Thank you.
 
Something like this:

Code:
awk --re-interval '
        {
                [olive]for[/olive] (i=1; i<=[blue]NF[/blue]; i++) {
                        [olive]if[/olive] ([blue]$i[/blue] ~ [green]/^[0-9]{2,3}-[0-9]{2,3}-/[/green]) { [b]print[/b] [blue]$i[/blue] }
                }
        }
' inputfile

Note that the {2,3} Extended Regular Expression syntax is not supported by normal awk, so you need to use GNU awk with the --re-interval option.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top