The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Operating Systems
> Linux Help
|
Listing files using pattern matching
Discuss Listing files using pattern matching in the Linux Help forum on Dev Shed. Listing files using pattern matching Linux Help forum discussing topics including usage, troubleshooting, modules, and distributions. Linux is an open source OS, based on UNIX.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

March 13th, 2011, 10:11 AM
|
|
Registered User
|
|
Join Date: May 2008
Posts: 22
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.
|

March 13th, 2011, 10:36 PM
|
|
Registered User
|
|
Join Date: May 2008
Posts: 22
Time spent in forums: 4 h 5 m 10 sec
Reputation Power: 0
|
|
|
any thoughts...please help
|

March 14th, 2011, 12:09 AM
|
|
Registered User
|
|
Join Date: Mar 2011
Posts: 12
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
|

March 15th, 2011, 07:28 AM
|
|
|
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
|

March 16th, 2011, 11:27 AM
|
|
Registered User
|
|
Join Date: May 2008
Posts: 22
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.
|

March 17th, 2011, 02:06 PM
|
|
Registered User
|
|
Join Date: May 2008
Posts: 22
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
|

March 19th, 2011, 12:33 AM
|
|
Registered User
|
|
Join Date: May 2008
Posts: 22
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
|

March 20th, 2011, 08:03 AM
|
|
|
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
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|