LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-27-2009, 10:44 AM   #1
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,231

Rep: Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914
regex with numbers in sequence


hi, how do i filter the following:
Code:
schneidz@lq:lq> ls -1
09-04-19
09-04-20
09-04-21
09-04-22
09-04-23
09-04-24
schneidz@lq:lq> ls -1 09-04-2[1-3]
09-04-21
09-04-22
09-04-23
schneidz@lq:lq> ls -1 09-04-[19-23]
ls: 0653-341 The file 09-04-[19-23] does not exist.
thanks,
 
Old 04-27-2009, 12:59 PM   #2
jan61
Member
 
Registered: Jun 2008
Posts: 235

Rep: Reputation: 46
Moin,

the expressions are no regex, but shell pathname globbing patterns. You can't filter it in one expression, use 2:
Code:
ls -1 09-04-19 09-04-2[0-3]
Jan
 
Old 04-27-2009, 02:30 PM   #3
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,231

Original Poster
Rep: Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914
i was actually using it in find in a shell script so it seems i will have to do a few find commands in a directory with a lot of stuff in it (going back two years). so it will take a while -- wish there was a better way.

thanks for the info,
 
Old 04-27-2009, 03:53 PM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 16,653

Rep: Reputation: 2453Reputation: 2453Reputation: 2453Reputation: 2453Reputation: 2453Reputation: 2453Reputation: 2453Reputation: 2453Reputation: 2453Reputation: 2453Reputation: 2453
Try using something like "seq" to generate a sequence and use that as a variable in a "for" loop.
Should be many ways to get it done.
 
Old 04-27-2009, 04:27 PM   #5
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,186

Rep: Reputation: 347Reputation: 347Reputation: 347Reputation: 347
From man find in the tests section:
Code:
       -newerXY reference
              Compares the timestamp of the current file with reference.  The reference  argument  is
              normally  the name of a file (and one of its timestamps is used for the comparison) but
              it may also be a string describing an absolute time.  X  and  Y  are  placeholders  for
              other  letters,  and these letters select which time belonging to how reference is used
              for the comparison.

              a   The access time of the file reference
              B   The birth time of the file reference
              c   The inode status change time of reference
              m   The modification time of the file reference
              t   reference is interpreted directly as a time

              Some combinations are invalid; for example, it is invalid for X to be t.  Some combina-
              tions  are  not  implemented on all systems; for example B is not supported on all sys-
              tems.  If an invalid or unsupported combination of  XY  is  specified,  a  fatal  error
              results.   Time  specifications are interpreted as for the argument to the -d option of
              GNU date.  If you try to use the birth time of a reference file,  and  the  birth  time
              cannot  be  determined,  a  fatal  error  message results.  If you specify a test which
              refers to the birth time of files being examined, this test will  fail  for  any  files
              where the birth time is unknown.
The are also "not" operators and "and" operators, so you can easily build a test like, e.g., -newerat '02-18-2009' -a ! -newerat '02-28-2009'.

Note: Untested code.

Last edited by PTrenholme; 04-28-2009 at 09:51 AM.
 
Old 04-28-2009, 01:20 PM   #6
jan61
Member
 
Registered: Jun 2008
Posts: 235

Rep: Reputation: 46
Moin,

Quote:
Originally Posted by PTrenholme View Post
...
The are also "not" operators and "and" operators, so you can easily build a test like, e.g., -newerat '02-18-2009' -a ! -newerat '02-28-2009'.
This will test the access timestamp on the files, not the names.

Jan

@schneidz: At least with GNU find you can use regex (the -regex and -iregex options). A matching regex for your sample is: '09-04-(19)|(2[0-3])'

Jan
 
1 members found this post helpful.
Old 04-28-2009, 06:52 PM   #7
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,186

Rep: Reputation: 347Reputation: 347Reputation: 347Reputation: 347
Quote:
Originally Posted by jan61 View Post
Moin,



This will test the access time stamp on the files, not the names.

Jan
[...]
Oops! My bad! I misread the name as dates.

Anyhow, my point about combining multiple test with -a, -o and ! operators does, I hope, remain valid.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Predicting Solaris 10 TCP Sequence Numbers Part 1: Initial Discovery LXer Syndicated Linux News 0 12-02-2008 01:10 PM
regex with sed to process file, need help on regex dwynter Linux - Newbie 5 08-31-2007 05:10 AM
manipulating 64 bit numbers using 32 bit numbers. rajesh_b Programming 3 09-15-2006 09:03 AM
sequence of numbers, how to extract which numbers are missing jonlake Programming 13 06-26-2006 03:28 AM
Adding numbers, break on non-numbers... Cruger Programming 1 03-22-2004 09:18 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:33 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration