The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
.
google unix.com



UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
find the length of file names in a directory? koti_rama Shell Programming and Scripting 5 06-04-2008 11:19 AM
Help With Double Sustitution Mohammed Shell Programming and Scripting 1 08-13-2007 03:53 AM
how to find capital letter names in a file without finding words at start of sentence kev269 Shell Programming and Scripting 1 04-10-2006 10:35 PM
find computer names from IP addresses? sladuuch IP Networking 1 10-07-2005 08:29 PM
find command not giving file names accord. to timestamps thanuman UNIX for Dummies Questions & Answers 8 09-07-2004 10:04 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 09-21-2007
baanprog baanprog is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 22
Find File names with sustitution

Hi All,

Iam trying to find two kinds of files while ignoring rest of the files in a directory

The files are like below

Files to be found
--------------------
perp45560
oerp4556

Files to be ignored
----------------------
oerp4556123450
oerp4556123470

I was trying the following in SunOS 5.10

find /mydir/files -name "[po]erp4556[?]" it is NOT working

if i use

find /mydir/files -name "[po]erp4556*"

it lists the files to be ignored also

if i use

find /mydir/files -name "[po]erp4556[0]"

it lists only "p" kind of files and ignores "o" kind.

the problem is simple while "p" files have a "0" [Read as zero] at the end, "o" files dont have anything. How to write a find command to find both simultaeneously while it should ignore other longer "p" or "o" files.

I would appreciate your help.

Regards
  #2 (permalink)  
Old 09-21-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,540
-name only knows shell patterns..
Code:
find /path \( -name perp* -o -name oerp* \) -ls
  #3 (permalink)  
Old 09-21-2007
radoulov's Avatar
radoulov radoulov is online now Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,890
1.

Code:
$ ls
oerp4556        oerp4556123450  oerp4556123470  perp45560
$ find . -name 'oerp4556' -o -name 'perp45560'
./perp45560
./oerp4556
If your find supports the regex option:

Code:
$find -regextype posix-extended -regex '.*[op]erp45560{,1}'
./oerp4556
./perp45560

2. With ksh,bash and zsh you can use ksh or extended-globbing, but you can do a recursive search only with the Z-Shell:

[ksh]
Code:
$ echo *
oerp4556 oerp4556123450 oerp4556123470 perp45560
$ echo [op]erp4556?(0)
oerp4556 perp45560
[bash]
Code:
bash 3.2.25(1)$ shopt -s extglob
bash 3.2.25(1)$ echo [op]erp4556?(0)
oerp4556 perp45560

[zsh]
Code:
zsh 4.3.4% setopt kshglob
zsh 4.3.4% echo [op]erp4556(?(0))
oerp4556 perp45560
or recursive:

Code:
setopt kshglob
print -l **/[op]erp4556(?(0))
  #4 (permalink)  
Old 09-26-2007
xramm xramm is offline
Registered User
  
 

Join Date: May 2007
Posts: 113
Quote:
Originally Posted by baanprog View Post
Hi All,

Iam trying to find two kinds of files while ignoring rest of the files in a directory

The files are like below

Files to be found
--------------------
perp45560
oerp4556

Files to be ignored
----------------------
oerp4556123450
oerp4556123470

I was trying the following in SunOS 5.10

find /mydir/files -name "[po]erp4556[?]" it is NOT working

if i use

find /mydir/files -name "[po]erp4556*"

it lists the files to be ignored also

if i use

find /mydir/files -name "[po]erp4556[0]"

it lists only "p" kind of files and ignores "o" kind.

the problem is simple while "p" files have a "0" [Read as zero] at the end, "o" files dont have anything. How to write a find command to find both simultaeneously while it should ignore other longer "p" or "o" files.

I would appreciate your help.

Regards
special chars like * ? do not work in brackets [], so try this,

find /mydir/files -name "[po]erp4556?"
  #5 (permalink)  
Old 09-26-2007
radoulov's Avatar
radoulov radoulov is online now Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,890
Quote:
Originally Posted by xramm View Post
special chars like * ? do not work in brackets [], so try this,

find /mydir/files -name "[po]erp4556?"
Here ? is any character, not only 0 and this doesn't glob "oerp4556".
Closed Thread

Bookmarks

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:12 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0