[ILUG] regex newbie question
Padraig Kitterick
info at padraigkitterick.com
Fri Aug 8 17:32:08 IST 2008
What version of grep are you running?
Hanafin, Jenny wrote:
> Hi Padraig,
>
> I've tried that egrep expression and egrep hung, so I put quotes around it and it worked, but returned no matches. I'm not finding that egrep is any more consistent than grep, though, this is a result I got from playing around a bit with your suggested expression:
>
> [219]: ls /data/gps/TEMP | egrep '^[[:alpha:]]{4}[0-9]{3}[a-x]'
> MACE213h.08n MACE213h.08o mace.lst VLNT160z.08n VLNT160z.08o
> VLNT213l.08n VLNT213l.08o VLNT.apr vlnt.lst
>
> so egrep is still returning 'vlnt.lst' which contains no digits. Trying Rory's suggestion gave no matches, but again I played around with it and got the following:
>
> [223]: ls /data/gps/TEMP | perl -nle 'print if(/[a-z]{4}\d{3}/)'
> BELF160z.08o BELF.apr dwnld.lst hers1600.08d itrf05_eura.apr
>
> Wha? Now where did that come from? I'm seeing no apparent logic,but maybe I'm not getting the syntax right.
>
> Jenny
>
> Try:
>
> ls /data/gps/TEMP | egrep ^[[:alpha:]]{4}[0-9]{3}[a-x]\\.[0-9]{2}[on]$
>
> Padraig.
>
> Hanafin, Jenny wrote:
>> Hi guys,
>>
>> I'm trying to come to grips with grep and regular expressions and while I'm making progress, I've come up with some things that puzzle me. Can someone explain to me why grep is returning the following, given the regex I'm using:
>>
>> [131] ls /data/gps/TEMP
>> BELF160z.08o BELF.apr dwnld.lst hers1600.08d itrf05_eura.apr lfile.VLNT MACE160z.08n MACE160z.08o MACE208o.08n MACE208o.08o MACE213h.08n MACE213h.08o mace.lst
>> VLNT160z.08n VLNT160z.08o VLNT213l.08n VLNT213l.08o VLNT.apr vlnt.lst
>> [132] ls /data/gps/TEMP | grep '^[[:alpha:]]\{4\}[0-9]\{3\}[a-x]\.[0-9]\{2\}[o|n]$'
>> [133] ls /data/gps/TEMP | grep '^[[:alpha:]]\{4\}[0-9]\{3\}[a-x]\.[0-9]\{2\}[o|n]'
>> MACE213h.08n MACE213h.08o mace.lst VLNT160z.08n VLNT160z.08o
>> VLNT213l.08n VLNT213l.08o VLNT.apr vlnt.lst
>>
>> What I want is an expression that only returns filenames with a specific format: 4 alphabetic characters, followed by 3 numeric, 1 alphabetic (a-x only), a period, 2 numeric characters and an "o" or an "n" at the end. This is what I think line [132] should return, and I don't understand why the first expression doesn't match any of the filenames. I also don't understand why filenames like 'vlnt.lst' are matched following the command in line [133].
>>
>> The problem seems to be with the [0-9] and I've tried using [[:digit:]] and [\d] instead but neither of those give me the answers I expect either!
>>
>> Any help appreciated, expecially at 4:30 on a Friday ;-)
>>
>> Thanks,
>>
>> Jenny
>>
>>
More information about the ILUG
mailing list