Linux Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsOperating SystemsLinux Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 13th, 2011, 10:11 AM
reference2me reference2me is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 22 reference2me User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 5 m 10 sec
Reputation Power: 0
Listing files using pattern matching

I have a requirement to list files using find command

My folder contains below list of files with out extention.

ABC.123.MNO.1234
ABC.123.1234
ABC.123.7890
ABC.123.MNO.654
KLM.123.MNO.456

File with extension

ABC.123.1234.txt

I have a requirement to exclude only ABC.123.* type files and list others. Even though files having MNO contains this pattern i should not exclude. Even if file ends with .txt or .doc it should not be excluded. That is ABC.123.1234.txt should not be excluded.

So I am writing my find command as

find -type f ! -name "ABC.[0-9].[0-9]*^."

But I am not getting what is required. Can any one please let me know if I am doing wrong any where. As per my requirement I cannot use grep, -regex, or -regex attributes to find command.

Reply With Quote
  #2  
Old March 13th, 2011, 10:36 PM
reference2me reference2me is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 22 reference2me User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 5 m 10 sec
Reputation Power: 0
any thoughts...please help

Reply With Quote
  #3  
Old March 14th, 2011, 12:09 AM
morean51 morean51 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2011
Posts: 12 morean51 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 13 m 58 sec
Reputation Power: 0
facing same sought of problem as my team lead had gave this work to me and started shunting please can anyone help me too also

Reply With Quote
  #4  
Old March 15th, 2011, 07:28 AM
SimonJM SimonJM is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Mar 2006
Posts: 2,108 SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 1 Day 4 h 50 m 50 sec
Reputation Power: 1485
Quote:
Originally Posted by reference2me
I have a requirement to list files using find command

...

But I am not getting what is required. Can any one please let me know if I am doing wrong any where. As per my requirement I cannot use grep, -regex, or -regex attributes to find command.

Any reason why you are not allowed to use -regex, etc.? That makes it smack of homework.
__________________
The moon on the one hand, the dawn on the other:
The moon is my sister, the dawn is my brother.
The moon on my left and the dawn on my right.
My brother, good morning: my sister, good night.
-- Hilaire Belloc

Reply With Quote
  #5  
Old March 16th, 2011, 11:27 AM
reference2me reference2me is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 22 reference2me User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 5 m 10 sec
Reputation Power: 0
Simon,

Actually there are many find based conditions in the script..i guess..the only thought might be is that using regex may disturb others..however, now it is fine. I was approved to use regex.

So, I tried using like this.

find -type f ! -regex "ABC.[0-9].[0-9]*^."

Still it is not working. Can you help me.

Reply With Quote
  #6  
Old March 17th, 2011, 02:06 PM
reference2me reference2me is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 22 reference2me User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 5 m 10 sec
Reputation Power: 0
i tried as below but still not working

find -type f ! -regex "/ABC.[0-9].[0-9]*^./"

please help

Reply With Quote
  #7  
Old March 19th, 2011, 12:33 AM
reference2me reference2me is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 22 reference2me User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 5 m 10 sec
Reputation Power: 0
Please let me know if there is any wrong in the syntax

Reply With Quote
  #8  
Old March 20th, 2011, 08:03 AM
SimonJM SimonJM is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Mar 2006
Posts: 2,108 SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level)SimonJM User rank is General 8th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 1 Day 4 h 50 m 50 sec
Reputation Power: 1485
Sorry not to have responded - had some timing and power issues ...!
If I find (pardon the pun!) that I have to use negation when doing things, what I often do is invert the negation and start simple, just to prove what I'm trying actually works.
What you will find is that the -regex operator deals with the entire path string returned by the find which is unlike the -name operator which acts purely and wholly on the name.
Assuming a directory content of:
Code:
ABC.123.1234
ABC.123.1234.txt
ABC.123.7890
ABC.123.7890.txt
ABC.123.MNO.1234
ABC.123.MNO.1234.txt
ABC.123.MNO.654
ABC.123.MNO.654.txt
KLM.123.MNO.456
KLM.123.MNO.456.txt

My initial stab is as follows. It is almost certainly wrong since trying to exclude from exclusions can be a little hard to follow!
Code:
find . -maxdepth 1 -regextype posix-basic -type f ! -regex "^./ABC.*.[0-9]$" -o -name "*MNO*"
./ABC.123.MNO.1234
./ABC.123.MNO.654
./KLM.123.MNO.456
./ABC.123.MNO.1234.txt
./ABC.123.1234.txt
./ABC.123.7890.txt
./ABC.123.MNO.654.txt
./KLM.123.MNO.456.txt

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsLinux Help > Listing files using pattern matching

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap