Find File names with sustitution


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Find File names with sustitution
# 1  
Old 09-21-2007
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  
Old 09-21-2007
-name only knows shell patterns..
Code:
find /path \( -name perp* -o -name oerp* \) -ls

# 3  
Old 09-21-2007
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  
Old 09-26-2007
Quote:
Originally Posted by baanprog
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  
Old 09-26-2007
Quote:
Originally Posted by xramm
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".
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find matching file in bash with variable file names but consisent prefixs

As part of a bash the below line strips off a numerical prefix from directory 1 to search for in directory 2. for file in /home/cmccabe/Desktop/comparison/missing/*.txt do file1=${file##*/} # Strip off directory getprefix=${file1%%_*.txt} ... (5 Replies)
Discussion started by: cmccabe
5 Replies

2. UNIX for Advanced & Expert Users

Find 2 occurrences of a word and print file names

I was thinking something like this but it always gets rid of the file location. grep -roh base. | wc -l find . -type f -exec grep -o base {} \; | wc -l Would this be a job for awk? Would I need to store the file locations in an array? (3 Replies)
Discussion started by: cokedude
3 Replies

3. Shell Programming and Scripting

Problems with script to find file names

Have a text file "test-array.txt" with contents below a23003 b23406 c23506 Tying to read the above file into an array and search for file-names in a directory TEST_DIR ,recursively with the above names in them. Example: If TEST_DIR has a files named xyxa_a23003_test.sql,... (4 Replies)
Discussion started by: gaurav99
4 Replies

4. Shell Programming and Scripting

find specific file names and execute a command depending on file's name

Hi, As a newbie, I'm desperate ro make my shell script work. I'd like a script which checks all the files in a directory, check the file name, if the file name ends with "extracted", store it in a variable, if it has a suffix of ".roi" stores in another variable. I'm going to use these two... (3 Replies)
Discussion started by: armando110
3 Replies

5. Shell Programming and Scripting

How to find complete file names in UNIX if i know only extention of file

Suppose I have a file which contains other file names with some extention . text file containt gdsds sd8ef g/f/temp_temp.sum yyeta t/unix.sum ghfp hrwer h/y/test.text.dat if then.... I want to get the complete file names, like for above file I should get output as temp_temp.sum... (4 Replies)
Discussion started by: panchal
4 Replies

6. Shell Programming and Scripting

How to find pattern in file names?

I have some files, those are abbreviated (ed,ea, and bi) company_ed_20100719.txt company_ea_20100719.txt company_bi_20100719.txt I would like to rename these files by replacing ed with EmployeeDetails ea with EmployeeAddress bi with BankInfomration as company_... (3 Replies)
Discussion started by: LinuxLearner
3 Replies

7. AIX

find for specific content in file in the directory and list only file names

Hi, I am trying to find the content of file using grep and find command and list only the file names but i am getting entire file list of files in the directory find . -exec grep "test" {} \; -ls Can anyone of you correct this (2 Replies)
Discussion started by: madhu_Jagarapu
2 Replies

8. UNIX for Dummies Questions & Answers

Find and replace portion of file names

Hey all, So I know you can easily find and replace words and strings in text files, but is there an easy way to find and replace just a sub-portion of text in the file name. For example, in a directory I have tons of file names that start with F00001-0708, and I want to change all the files to... (2 Replies)
Discussion started by: hertingm
2 Replies

9. Shell Programming and Scripting

Find the file names from date/time: Need help

Hi All, I really need help in figuring out how to determine the filenames from the time that is specified as parameter. The script should take as input - the start time and end time in minutes and also start date and end date. Example: reporter.sh -instance Instance_Name -startTime 13:10... (0 Replies)
Discussion started by: chiru_h
0 Replies

10. Shell Programming and Scripting

find the length of file names in a directory?

Hi, how can find length of file names in a directory. Examp: I have a directory with name "d1". directory: d1 files: aaa.log bbb.log abcd.log abcdef.log I wold like out put like: file name legnth aaa.log 3 bbb.log 3 abcd.log 4 abcdef.log 5 (5 Replies)
Discussion started by: koti_rama
5 Replies
Login or Register to Ask a Question