Using ls command to display files for range of values only


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Using ls command to display files for range of values only
# 1  
Old 06-10-2013
Using ls command to display files for range of values only

Hi Forum.

I tried to search the forum for an answer but couldn't find it.

I have the following files in my directory:
Code:
PROFILE_TXN_61647.dat
PROFILE_TXN_61648.dat
PROFILE_TXN_61649.dat
PROFILE_TXN_61650.dat
PROFILE_TXN_61651.dat
PROFILE_TXN_61652.dat
PROFILE_TXN_61653.dat
PROFILE_TXN_61654.dat
PROFILE_TXN_61655.dat
PROFILE_TXN_61656.dat
PROFILE_TXN_61657.dat
PROFILE_TXN_61658.dat
PROFILE_TXN_61659.dat
PROFILE_TXN_61660.dat
....  
PROFILE_TXN_61900.dat

I want to get a listing of files ranging from 61649 to 61979

Thanks for your help.
# 2  
Old 06-10-2013
Code:
for i in {61649..61979}; do 
   if [ -f  PROFILE_TXN_${i}.dat ] ; then 
      ls -l PROFILE_TXN_${i}.dat
   fi 
done

# 3  
Old 06-10-2013
Thank you - I was thinking that can it be done with a one line command?
# 4  
Old 06-10-2013
In bash you can use a sequence expression:
Code:
ls PROFILE_TXN_{61649..61979}.dat

# 5  
Old 06-10-2013
Quote:
Originally Posted by Yoda
In bash you can use a sequence expression:
Code:
ls PROFILE_TXN_{61649..61979}.dat

This also works with recent versions of the Korn shell, but I don't remember which version of ksh93 added it.
# 6  
Old 06-10-2013
Quote:
Originally Posted by Don Cragun
This also works with recent versions of the Korn shell, but I don't remember which version of ksh93 added it.
I don't know bash, but i wonder: does this work like a glob or like parameter expansion? In case of the latter there should be an error message if one of the files is missing, yes?

bakunin
# 7  
Old 06-10-2013
Quote:
Originally Posted by pchang
Thank you - I was thinking that can it be done with a one line command?
In that case try this...
Code:
ls -latr | grep -E "PROFILE_TXN_61(649|[6-9][5-7][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

Display files within a range

My script reads all the log files in a directory, the user would enter a range and the script would only display the files within those range. Here's my code: #!/bin/bash LOG_FILES=("Sandbox/logs/*") for file in ${LOG_FILES}; do echo $file; done ------------- for i in $(seq $1 $2); do... (1 Reply)
Discussion started by: Loc
1 Replies

2. Shell Programming and Scripting

Create range of values and count values.

Gents, It is possible to generate a range of values according to column 1 and count the total of rows in the range. example input 15.3 15.5 15.8 15.9 16.0 16.1 16.8 17.0 17.5 18.0 output desired 15.0 - 15.9 = 4 (10 Replies)
Discussion started by: jiam912
10 Replies

3. Shell Programming and Scripting

Convert Column Values to a Range of Values

I have a list of columns with values that I need to transform into a row containing the range of each column. For example: "Column A" 1 2 3 4 10 12 14 15 16 17 18 "Column B" 1 4 5 6 (4 Replies)
Discussion started by: newbio
4 Replies

4. UNIX for Dummies Questions & Answers

How to display lines by range specified?

My input file is N3*123 ABC FLATS~ REF*D9*10000000001~ N3*223 ABC FLATS~ REF*D9*10000000002~ N3*323 ABC FLATS~ REF*D9*10000000003~ N3*423 ABC FLATS~ REF*D9*10000000004~ N3*523 ABC FLATS~ REF*D9*10000000005~ N3*623 ABC FLATS~ REF*D9*10000000006~ N3*723 ABC FLATS~ REF*D9*10000000007~ N3*823... (2 Replies)
Discussion started by: nsuresh316
2 Replies

5. Shell Programming and Scripting

Display data from a range of dates

I have a data in a file called SCHED which has 5 columns: sched no, date, time, place and remarks. The image is shown below. http://dl.dropbox.com/u/54949888/Screenshot%20from%202013-01-02%2002%3A42%3A25.png Now, I want to display only the schedules which fall under a certain date range which... (2 Replies)
Discussion started by: angilulu
2 Replies

6. UNIX for Dummies Questions & Answers

Display dates within a given date range

Hi All, I have a requirement to display all the dates within the provided (through user input) date range. For eg: If I enter 28012009 (as From date in the format 'DDMMYYYY') and 02022009(as To date in the format 'DDMMYYYY'), the output should be all dates occuring between the from and to... (11 Replies)
Discussion started by: sunpraveen
11 Replies

7. Shell Programming and Scripting

display the file with in the date range

Hi All, I want a shell script which can display the file with in the date range. For Example I have 15 files with the following format abc_01-01-2009.txt to abc_15-01-2009.txt. Now I want to have the files between 4th of jan to 12th files. How can I acheive this. Advance... (1 Reply)
Discussion started by: fareed_do
1 Replies

8. Solaris

What command can display files in a tree?

Is there a command that displays a certain path of files in a tree just like the dos command 'tree'? (17 Replies)
Discussion started by: Bradj47
17 Replies

9. UNIX for Dummies Questions & Answers

How to display files that have been modifed between a given date range

Hi, I am new to Unix and was trying different ways of how to display the list of file names modified between a given date range in sorting order.I will get the fromdate and Todate from the browser, I need to display the list of all the file names that are modified between the given date... (1 Reply)
Discussion started by: prathima
1 Replies

10. UNIX for Dummies Questions & Answers

How to Display a range of values in the output of cat

When I use this command I get an output of some numbers cat ac.20070511 | cut -d" " -f19 Is there any way for me to display only the numbers that are greater than 1000 but not all the numbers in the ouput. Can any one help me with this. :) (8 Replies)
Discussion started by: venu_nbk
8 Replies
Login or Register to Ask a Question