How to select only those file names whose name contains only numerals.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to select only those file names whose name contains only numerals.
# 1  
Old 07-14-2009
How to select only those file names whose name contains only numerals.

Hi Guru's,

Before writing to this forum I have searched extensively on this forum about my problem.

I have to write a shell script which takes out only those file names from the given directory which contains only numbers. For example, In the given directory these files are present:

11059813.xls
59813.xls
059813.xls
813.xls
Names_0767957.xls
Summary.xls

So out of the above file names, the script output should select only the files whose name consists of numbers i.e.

11059813.xls
59813.xls
059813.xls
813.xls

I am a novice in this area. Please help me out all Guru's, as this is urgent for me.

Thanks.
# 2  
Old 07-14-2009
if your shell is posix-sh compatible (ksh, bash, ...), then

filename generation rule:
+([0-9]).xls

echo +([0-9]).xls
ls +([0-9]).xls
for f in +([0-9]).xls
...
# 3  
Old 07-14-2009
I am closing this thread. It is a duplicate of a thread in another forum.
# 4  
Old 07-14-2009
Hi,
Moderators.. Can you please do us a favor..
While closing duplicate threads, can you please post the link of the duplicate thread so that users searching for the duplicate thread can get it easily? As there is probability of a more/better answers in the duplicate thread.
I hope you do see some valid reason here.
Thanks.
# 5  
Old 07-14-2009
Running the following in your directory:
Code:
ls | grep [[:digit:]]

Will list only those files that have a number in the name.

HTH
# 6  
Old 07-15-2009
Code:
ls | egrep '^[0-9]+\.'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Exclude certain file names while selectingData files coming in different names in a file name called

Data files coming in different names in a file name called process.txt. 1. shipments_yyyymmdd.gz 2 Order_yyyymmdd.gz 3. Invoice_yyyymmdd.gz 4. globalorder_yyyymmdd.gz The process needs to discard all the below files and only process two of the 4 file names available ... (1 Reply)
Discussion started by: dsravanam
1 Replies

2. Programming

Query to SELECT only Column Names that Contain a Specific String?

Hey Guys, I'm using SQuirreL SQL v3.5 GUI to fetch some data that I need for something I'm working on. I'm also using the IBM Informix Driver (*Version 3.5) to connect to the Database. What I want to do, if it's even possible, is to show all COLUMNS if they contain the word "Email". So in... (2 Replies)
Discussion started by: mrm5102
2 Replies

3. Shell Programming and Scripting

Sort roman numerals

If I use ls to print all the files of a folder, is there a way to sort using roman numerals? I am thinking about a result like: benjamin_I.wmv benjamin_II.wmv benjamin_II.wmv benjamin_III.wmv benjamin_IV.wmv benjamin_V.wmv benjamin_VI.wmv benjamin_VII.wmv benjamin_VIII.wmv... (6 Replies)
Discussion started by: locoroco
6 Replies

4. Shell Programming and Scripting

Compare file names and select correct elements to include in "for each loop"

Hi everyone, I`ll try to be most clear I can explaining my help request. I have 2 folders Folder A-->This folder receives files through FTP constantly Folder B-->The files from Folder A are unzipped and then processed in Folder B Sometimes Folder A doesn`t contain all... (2 Replies)
Discussion started by: cgkmal
2 Replies

5. Shell Programming and Scripting

Searching for file names in a directory while ignoring certain file names

Sun Solaris Unix Question Haven't been able to find any solution for this situation. Let's just say the file names listed below exist in a directory. I want the find command to find all files in this directory but at the same time I want to eliminate certain file names or files with certain... (2 Replies)
Discussion started by: 2reperry
2 Replies

6. UNIX for Advanced & Expert Users

How to select only those file names whose name contains only numbers

Hi Guru's, Before writing to this forum I have searched extensively on this forum about my problem. I have to write a shell script which takes out only those file names from the given directory which contains only numbers. For example, In the given directory these files are present: ... (4 Replies)
Discussion started by: spranm
4 Replies

7. UNIX for Dummies Questions & Answers

How to select only those file names whose name contains only numbers.

Hi Guru's, Before writing to this forum I have searched extensively on this forum about my problem. I have to write a shell script which takes out only those file names from the given directory which contains only numbers. For example, In the given directory these files are present: ... (0 Replies)
Discussion started by: spranm
0 Replies

8. UNIX for Dummies Questions & Answers

Using CUT command to get only numerals from a string

I need help to get only the numerals from a string Ex : var1=Nightfox has 2 red apple(s) I need to cut only the numeral 2 and move it to a variable. var2=`$var1 | cut -c 14` the cut by character doesnt work, how to get only the numeral ? (2 Replies)
Discussion started by: happyrain
2 Replies

9. Shell Programming and Scripting

extracting only numerals from string.

Hi!!! i have two files "tushar20090429200000.txt" and "tushar_err20090429200000.txt" The numeric part here is date and time. So this part of file keeps changing after every hour. I want to extract the numeric part from the both file names and compare them whether they are equal or not. ... (4 Replies)
Discussion started by: tushar_tus
4 Replies

10. Shell Programming and Scripting

Extracting Table names from a Select Stament

Hi, I am working on a code to extract the table names out of a select statement. Is there anybody who has worked on something similar? May be you could provide me with the regular expression for the same. Regards. Silas (2 Replies)
Discussion started by: silas.john
2 Replies
Login or Register to Ask a Question