[Linux OT] Regular expresion question

Brad De Vries devriesbj
Mon Oct 4 15:50:51 PDT 2004


On Mon, 04 Oct 2004 14:25:24 -0500, Jean Sagi <jeansagi at uniweb.net.co> wrote:
> 
> Hi all,
> 
> Maybe anyone could help with a regular expresion for matching a rabge of
> numbers.
> 
> Lets say You a have a file, in which each line is string of the form:
> hddmmyy, where h is the char 'h' and dd is a day (01..31), mm is a month
> (01..12) and yy are the last two digists of the current year.
> 
> So the file could be:
> 
> h030904
> h300904
> h290904
> h040904
> h090904
> h100904
> h120904
> h150904
> h180904
> h020904
> h190904
> h220904
> h050904
> h240904
> h207904
> 
> All these represent files created in some days of september this year.
> 
> What I want is to get a regular expresion wich matches a range of days,
> for example the files representing day 10 through 25 for instance, with
> the previous example the next sould match:
> 
> h100904
> h120904
> h150904
> h180904
> h190904
> h220904
> h240904
> h207904
> 
> Some kind of this expresion
> 
> ^h<range expresion>09
> 
> where <range expresion> is a pattern that matches:
> 10
> 11
> 12
> 13
> 14
> 15
> 16
> 17
> 18
> 19
> 20
> 21
> 22
> 23
> 24
> 25
> 
> so that files like
> 
> h100904
> h110904
> h120904
> h130904
> h140904
> h150904
> h160904
> h170904
> h180904
> h190904
> h200904
> h210904
> h220904
> h230904
> h240904
> h250904
> 
> Be matched
> 
> I could acomplish what I'm asking with awk but I'm wondering if regular
> expresion could do the work.
> 
> Any help would be very appreciated.
> 
> Chucho!

Jean, you could try sed using the following syntax:
$ sed -n -e "/^h1[0-9].9/p" -e "/^h2[0-5].9/p"

Brad.


More information about the Linux-users mailing list