Display files within a range


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Display files within a range
# 1  
Old 05-03-2017
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:
Code:
 
 #!/bin/bash
 LOG_FILES=("Sandbox/logs/*")
 for file in ${LOG_FILES[@]}; do echo $file; done
 -------------
 for i in $(seq $1 $2); do echo $i; done

The first loop display all the files in the log directory. The second loop display numbers within that range. These 2 loops work but I don't know how to combine them together.
I would like the script to read all the files in the log directories and only echo out the files within a range of say, 20 to 24. So my output would be:
Code:
 
 server.logs-2017-04-20
server.logs-2017-04-21
server.logs-2017-04-22
server.logs-2017-04-23
server.logs-2017-04-24

Any suggestions? tks
# 2  
Old 05-03-2017
What do you call a range? A number / sequence of days? Within a month? Do they span month boundaries? What if there are files from March or May?
For above, and with a recent bash, try
Code:
ls -1 server.logs-2017-04-{21..23}
server.logs-2017-04-21
server.logs-2017-04-22
server.logs-2017-04-23

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Display lines of two date range from syslog file

Hi Guys, I want to display lines from Solaris syslog file but with 2 dates range. I have some similar solution (https://www.unix.com/shell-programming-scripting/39293-grep-log-file-between-2-dates-4.html) which works fine but as you know syslog has different date format (Jan 22) so this is not... (1 Reply)
Discussion started by: prashant2507198
1 Replies

2. UNIX for Dummies Questions & Answers

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: 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... (8 Replies)
Discussion started by: pchang
8 Replies

3. 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

4. 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

5. UNIX for Dummies Questions & Answers

Display lines after match is found within specified range

I have a file which has collection of segments occuring n(For eg.100) times ISA GS ST NM1*85 N3 N4 NM1*IL N3 N4 REF*D9*1001 ISE GE SE ISA GS ST NM1*85 N3 (13 Replies)
Discussion started by: nsuresh316
13 Replies

6. Shell Programming and Scripting

display Range of date depend on user input php

Hi, i am very new to php Is it possible to display Range of date depend on user input day example: user input 2 day start from 28/4/12 it will add 2 day from date of input so display should look like this 28/4/12 to 30/4/12 then from 30/412 user add another 4 date so will... (0 Replies)
Discussion started by: guidely
0 Replies

7. 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

8. 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

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