LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 05-16-2004, 03:18 AM   #1
jonathanztaub
LQ Newbie
 
Registered: May 2004
Posts: 14

Rep: Reputation: 0
grep usage with regular expression


I've got a directory filled with log files.
I need to find the log files which part of their name is a date.
The date format is YYYY-DD-MM, such as:
2004-16-05

I know I have to execute:

ls | grep <regular_expression>

I tried a little with regular expression:

*\d*-\d*-\d*

but it didn't work.

Can somebody help me with this regular expression?
Does grep's regular expression is different from what I tried?
 
Old 05-16-2004, 03:36 AM   #2
Berhanie
Senior Member
 
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
ls | egrep [0-9]{4}-[0-9]{2}-[0-9]{2}
the egrep would match exactly what you wanted, xxxx-xx-xx, where each of the "x"s is a possibly distinct digit
 
Old 05-16-2004, 03:41 AM   #3
bulliver
Senior Member
 
Registered: Nov 2002
Location: Edmonton AB, Canada
Distribution: Gentoo x86_64; Gentoo PPC; FreeBSD; OS X 10.9.4
Posts: 3,760
Blog Entries: 4

Rep: Reputation: 77
Well, if we assume that the year in the filename is always 2003, or 2004 then just use this:
Code:
 ls *{2003,2004}*
You may get a few false positives but it's easier than writing some cryptic regex...
If the files include other years just add them to the list.
 
Old 09-01-2004, 10:19 PM   #4
subaruwrx
Member
 
Registered: Mar 2004
Distribution: Ubuntu Feisty
Posts: 641

Rep: Reputation: 30
Quote:
Originally posted by bulliver
Well, if we assume that the year in the filename is always 2003, or 2004 then just use this:
Code:
 ls *{2003,2004}*
You may get a few false positives but it's easier than writing some cryptic regex...
If the files include other years just add them to the list.
How not use

Code:
ls *{2003|2004}*
Is it the same?
 
Old 09-01-2004, 10:54 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,005
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
No, it's not {,} is shell syntax, {|} is regex.

ls != grep

Can't mix those, the shell will give you an
error on the latter.



Cheers,
Tink
 
Old 09-01-2004, 11:01 PM   #6
subaruwrx
Member
 
Registered: Mar 2004
Distribution: Ubuntu Feisty
Posts: 641

Rep: Reputation: 30
Quote:
Originally posted by Tinkster
No, it's not {,} is shell syntax, {|} is regex.

ls != grep

Can't mix those, the shell will give you an
error on the latter.



Cheers,
Tink
You mean both of them are for "different application"? But their meaning is still the same?
 
Old 09-01-2004, 11:21 PM   #7
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,005
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
Indeed ...


btw, it would be nice if you didn't
dig up long dead threads to attach your queries
to them but instead either a) use the info you
found in them or b) ask a specific question in
a thread of your own.

This one here, and that one:
http://www.linuxquestions.org/questi...threadid=74014

Cheers,
Tink
 
Old 09-01-2004, 11:35 PM   #8
subaruwrx
Member
 
Registered: Mar 2004
Distribution: Ubuntu Feisty
Posts: 641

Rep: Reputation: 30
Quote:
Originally posted by Tinkster
Indeed ...


btw, it would be nice if you didn't
dig up long dead threads to attach your queries
to them but instead either a) use the info you
found in them or b) ask a specific question in
a thread of your own.

This one here, and that one:
http://www.linuxquestions.org/questi...threadid=74014

Cheers,
Tink
Oh sorry about that.

Will take note.
 
  


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with regular expression aecaudel Programming 6 11-04-2005 06:28 AM
problems with regular expression and grep bwreath Linux - General 6 03-18-2005 02:43 PM
Need help with Regular Expression subaruwrx Linux - Newbie 6 09-04-2004 08:48 PM
Regular Expression Help WeNdeL Linux - General 1 08-14-2003 11:08 AM
regular expression gumby Programming 3 07-15-2003 01:13 PM


All times are GMT -5. The time now is 12:23 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration