Bash list files with certain name range

I have a directory that contains txt files with unique times that gets generated overnight. I am trying to list those files given the unique timestamps in the file. Some example of file names are the following:

file_20210122_1130_1.txt 
file_20210122_1133_1.txt 
file_20210122_1221_1.txt 
file_20210122_1342_1.txt 
file_20210122_1721_1.txt 
file_20210122_1911_1.txt
file_20210122_2009_1.txt
file_20210122_2020_1.txt
file_20210122_2130_1.txt
...

I want the ability to list the files (using pattern contained in the filename itself) between 1900 and 2100 and it should list the following:

file_20210122_1911_1.txt
file_20210122_2009_1.txt
file_20210122_2020_1.txt

I am trying to use the below code snippet but it partially works and does NOT list all of the files.

cd /home/somedir/files;
ls *.txt | awk '/1900/,/2100/'

Any help would be appreciated.



Read more here: https://stackoverflow.com/questions/67942752/bash-list-files-with-certain-name-range

Content Attribution

This content was originally published by Anand Patel at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: