LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 06-16-2007, 10:25 AM   #1
ovince
Member
 
Registered: Mar 2007
Posts: 77

Rep: Reputation: 15
regexp


Hi,


I would like to distinguish between files with name

1. *specIDs.dat

2. *_IDs.dat


So I wrote:


Code:
for fl in `find -type f -name "*tau[1-6][!0-9]*_IDs.dat" -print`; do
 echo $fl;
done

Why this does not work? When I put
"*tau[1-6][!0-9]*IDs.dat" it works but finds 2. also.


thanks
o.
 
Old 06-16-2007, 10:54 AM   #2
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Try using "-regex" instead of "-name". Also, "*" itself doesn't do anything; it means "previous character repeated 0 or more times". That means you should have a "." (any character) before the first "*":
Code:
.*tau[1-6][!0-9]*_IDs.dat
So is this what you intend?
Code:
(anything consisting of 0 or more chars)("tau")(single char 1 through 6)(0 or more of "!" or 0 through 9)("_IDs.dat")
ta0kira

edit: If you mean "[!0-9]*" as "any group of something besides numbers" you need to change "!" to "^".

Last edited by ta0kira; 06-16-2007 at 10:56 AM.
 
Old 06-16-2007, 11:02 AM   #3
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
Quote:
"*" itself doesn't do anything; it means "previous character repeated 0 or more times"
That's true for a regex, but not for -name.

Last edited by wjevans_7d1@yahoo.co; 06-16-2007 at 11:04 AM.
 
Old 06-16-2007, 11:12 AM   #4
ovince
Member
 
Registered: Mar 2007
Posts: 77

Original Poster
Rep: Reputation: 15
I just have files with names:

file_tau1_IDs.dat
file_tau3_IDs.dat
file_tau5_IDs.dat
file_tau6_IDs.dat
so on ...

and I want to distinguish these from similar files

file_tau1_specIDs.dat
file_tau3_specIDs.dat
file_tau5_specIDs.dat
file_tau6_specIDs.dat
....

Numbers goes from 1 to 10
 
Old 06-16-2007, 11:27 AM   #5
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Code:
find -type f -regex "file_tau([1-9]|10)_IDs.dat"
Will that work? I don't seem to have luck with 'find' regex, so maybe you need to just 'egrep':
Code:
find -type f | egrep "/file_tau([1-9]|10)_IDs.dat$"
Quote:
Originally Posted by wjevans_7d1@yahoo.co
That's true for a regex, but not for -name.
Yes, I understand that. I was more pointing out that a regex isn't the same as a wildcard.
ta0kira

edit: forgot "tau"

Last edited by ta0kira; 06-16-2007 at 11:28 AM.
 
Old 06-16-2007, 12:00 PM   #6
ovince
Member
 
Registered: Mar 2007
Posts: 77

Original Poster
Rep: Reputation: 15
i was so unprecise with definition what I would like to do. sorry.

I have this kind of files in the different sub directories:

file_tau1_IDs.dat
file_tau3_specIDs.dat
file_tau5_IDs.dat
file_tau6_specIDs.dat
file_tau10_IDs.dat
file_tau2_specIDs.dat
so on ...

Numers running from 1 to 10. I would like to manipulate only files that contain
numbers 1 to 6 (ie no 7, 8, 9, 10) and only that with _IDs.dat (ie. no *_specIDs.dat).
Especially I have a problem to exclude file that has 10.
 
Old 06-16-2007, 12:18 PM   #7
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
find -regex '.*file_tau[1-6]_IDs.dat' | xargs someCmd
or just shell globbing would do for what you've just described:
someCmd file_tau[1-6]_IDs.dat

-- Oops. Need to read more carefully - shell globbing won't suffice if some are in subdirs. Though something like 'someCmd {,*/}file_tau[1-6]_IDs.dat' would work for one level of subdirs and so on.

Last edited by slakmagik; 06-16-2007 at 12:21 PM. Reason: re-read more carefully
 
Old 06-17-2007, 03:22 AM   #8
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
In that case the -exec option to find may be helpful?


Cheers,
Tink
 
Old 06-17-2007, 10:54 AM   #9
wjevans_7d1@yahoo.co
Member
 
Registered: Jun 2006
Location: Mariposa
Distribution: Slackware 9.1
Posts: 938

Rep: Reputation: 31
ovince, with all the suggestions and comments, I'd like to know: Is your original problem solved?
 
  


Reply



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
regexp help cliff76 Linux - Newbie 3 03-07-2008 02:15 PM
ls and regexp ygloo Programming 8 10-05-2006 03:50 PM
regexp stomach Linux - Software 7 02-15-2006 06:33 PM
little help for regexp EmOuBi Linux - Newbie 6 08-06-2005 02:19 AM
regexp help ... pld Programming 1 03-15-2005 03:45 PM

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

All times are GMT -5. The time now is 12:26 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
Open Source Consulting | Domain Registration