Finding files with filename format


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding files with filename format
# 1  
Old 10-28-2010
Finding files with filename format

hi all,

i'm trying to find out how to show files having a particular format. i.e.

files
o570345.out
o5703451.out
XX_570345_1.RTF

so when i search for files using
ls *570345*

it shows all three files but actually i don't like to see the second file o5703451.out because 5703451 is different from 570345. how do i go about this?

thanks

Last edited by adshocker; 10-28-2010 at 12:37 AM..
# 2  
Old 10-28-2010
egrep:
Code:
F=570345
echo *${F}* | grep -E '[^0-9]$F[^0-9]'
# ls *${F}* | grep -E '[^0-9]$F[^0-9]' # If the previous doesn't work

This User Gave Thanks to frans For This Post:
# 3  
Old 10-28-2010
the second code is good.

coz in first it will not show the desied result though those three file are a single line representation.
but the ls *${F}* is a three line representation of those three file before coming to grep.

welcome anytime,
Sanjay
This User Gave Thanks to sanjay.login For This Post:
# 4  
Old 10-28-2010
Code:
ls *[^0-9]570345[^0-9]*

This User Gave Thanks to rdcwayx For This Post:
# 5  
Old 10-28-2010
thank you all for your help.

just curious, what does the [^0-9] mean by appearing before and after?
# 6  
Old 10-28-2010
[^0-9] - means there should be no numbers between 0 to 9 appear before and after your filename (570345)
These 2 Users Gave Thanks to michaelrozar17 For This Post:
# 7  
Old 11-04-2010
thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding files with newlines in filename

I want to use grep to find files that have newlines in the filename. For example, I have a directory where I create three files: $ touch file1 $ touch "file 2" $ touch "file > with > newlines" $ find . ./file 2 ./file1 ./file?with?newlinesI now want to pipe the find output into grep and... (4 Replies)
Discussion started by: Ralph
4 Replies

2. Shell Programming and Scripting

Finding the part of a filename

Hi, I am writing an ebuild for Gentoo Linux operating system. Writing an ebuild is about Bash scripting where I am a newbie. So, my ebuild must find a part of a specific filename. Such a filaname my look like this: libvclient_release_x64.so.740and I must to find the number at the and of... (18 Replies)
Discussion started by: csanyipal
18 Replies

3. Shell Programming and Scripting

To find files having filename containing specific date format

Hi, I have a requirement to create a shell script(tcsh) that finds all the files in a directory having the file name containing date format "YYYYMMDDHHMM" and extract the date time part ""YYYYMMDDHHMM" for further processing. Could you please have any idea on this. trades_201604040000.out... (6 Replies)
Discussion started by: gopal.biswal
6 Replies

4. UNIX for Dummies Questions & Answers

Finding filename based on filecontent

Hi, I have been trying , to find the filename based on some pattern present inside the file My command is as follows: filename=`grep -l 'Pattern' path/*.txt ` Its strange that it works some times, but doesn't print anything some times . But my if test -f $filename is passing all the... (2 Replies)
Discussion started by: Prashanth19
2 Replies

5. Shell Programming and Scripting

Finding max number in filename and opening it

Hi, I have files named as energy.dat.1 energy.dat.2 energy.dat.3 ... energy.dat.2342 I would like to find the file with maximum number in the filename (ex. energy.dat.2342) and open it. Would you please share your expertize in writing the script? Thanks in advance. (8 Replies)
Discussion started by: rpd25
8 Replies

6. Shell Programming and Scripting

Finding files before a certain date with predefined format

Guys, I have an input file such as below I would like to know how i would be able to find items created before 2011-10-01 Appreciate any expert advice. Thanks. (3 Replies)
Discussion started by: aismann
3 Replies

7. UNIX for Dummies Questions & Answers

finding and moving files based on the last three numerical characters in the filename

Hi, I have a series of files (upwards of 500) the filename format is as follows CC10-1234P1999.WGS84.p190, all in one directory. Now the last three numeric characters, in this case 999, can be anything from 001 to 999. I need to move some of them to a seperate directory, the ones I need to... (5 Replies)
Discussion started by: roche.j.mike
5 Replies

8. Shell Programming and Scripting

finding files with unicode chars in the filename

I'm trying to check-in a repository to svn -- but the import is failing because some files waaaay down deep in some graphics-library folder are using unicode characters in the file name - which are masked using the ls command but picked up when piping output to more: # ls -l 1914* -rwxrwxr-x 1... (2 Replies)
Discussion started by: mshallop
2 Replies

9. Shell Programming and Scripting

Filename from splitting files to have the same filename of the original file with counter value

Hi all, I have a list of xml file. I need to split the files to a different files when see the <ko> tag. The list of filename are B20090908.1100-20090908.1200_CDMA=1,NO=2,SITE=3.xml B20090908.1200-20090908.1300_CDMA=1,NO=2,SITE=3.xml B20090908.1300-20090908.1400_CDMA=1,NO=2,SITE=3.xml ... (3 Replies)
Discussion started by: natalie23
3 Replies

10. Shell Programming and Scripting

finding duplicate files by size and finding pattern matching and its count

Hi, I have a challenging task,in which i have to find the duplicate files by its name and size,then i need to take anyone of the file.Then i need to open the file and find for more than one pattern and count of that pattern. Note:These are the samples of two files,but i can have more... (2 Replies)
Discussion started by: jerome Sukumar
2 Replies
Login or Register to Ask a Question