For Programmers: Free Programming Magazines  


Home > Archive > AWK > November 2004 > Re: confused with regular expression









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 Re: confused with regular expression
Ed Morton

2004-11-16, 6:50 pm



moggces wrote:
> Sorry
> I am not sure what was wrong.
>
> I have a file which has two pattern
>
> 5673058-
> AE-848/14271200-
>
> in command line I typed:
> awk '/^[0-9]/ { print }' file
> , tried to get "5673058-" but it printed nothing
> so I tried to type
> awk --re-interval '/[0-9]{7}/ { print}' file
> strangely, it didn't print "5673058-" but instead it printed "AE-848/14271200-"
>
> my gawk version is 3.1.4


Mine is 3.1.3 and it works as expected:

$ printf "5673058-\nAE-848/14271200-\n" | awk '/^[0-9]/ { print }'
5673058-

$ printf "5673058-\nAE-848/14271200-\n" | awk --re-interval '/[0-9]{7}/
{ print }'
5673058-
AE-848/14271200-

$ awk --version
GNU Awk 3.1.3

So, at least you know it isn't your RE(s). If grep or sed don't find
them, it's your file that's got control chars or something, otherwise
it's your gawk version.

Regards,

Ed.
moggces

2004-11-16, 6:50 pm

arnold@skeeve.com (Aharon Robbins) wrote in message news:<4188a048@news.012.net.il>...
> In article <BJ6dnfoEnfzB7xXcRVn-gw@comcast.com>,
> Ed Morton <morton@lsupcaemnt.com> wrote:
> "AE-848/14271200-"
>
> Actually, I'm 99% certain it's not the gawk version, but the locale; the
> original poster is in China. It's probably better to use
>
> /^[[:digit:]]/
>
> and
>
> /^[[:digit:]]{7}/
>
> instead of [0-9]. I suspect that if the original poster uses
>
> export LC_ALL=C
>
> before running gawk, things will work as expected.
>
> Arnold




It didn't work when I use /^[[:digit:]]/ without "export LC_ALL=C"

and both /^[0-9]/ and /^[[:digit:]]/ could work after "export LC_ALL=C"

Thanks very much for all responses

Jui-Hua
from Taiwan
Sponsored Links







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

Copyright 2009 codecomments.com