LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
Email to...
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] regex newbie question

[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
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


Maintained by the ILUG website team. The aim of Linux.ie is to support and help commercial and private users of Linux in Ireland. You can display ILUG news in your own webpages, read backend information to find out how. Networking services kindly provided by HEAnet, server kindly donated by Dell. Linux is a trademark of Linus Torvalds, used with permission. No penguins were harmed in the production or maintenance of this highly praised website. Looking for the Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!
RSS Version
Powered by Dell