One of my folders contains files in the following format:3_20150412104422154033.txt3_2015041211022775012.txt3_20150412160410171639.txt3_20150412160815638933.txt3_20150413161046573097.txt3_20150413161818852312.txt3_20150413163054600311.txt3_20150413163514489159.txt3_2015041321292659391.txt3_20150414124528747462.txt3_20150414125110440425.txt3_20150414134437706174.txt3_20150415085045179056.txt3_20150415100637970281.txt3_20150415101749513872.txtI want to retrieve those files having a date value less than or equal to my input date value.For example, if I give 3_20150414 which is (3_YYYYMMDD), I want the output to be the file names3_20150412104422154033.txt3_2015041211022775012.txt3_20150412160410171639.txt3_20150412160815638933.txt3_20150413161046573097.txt3_20150413161818852312.txt3_20150413163054600311.txt3_20150413163514489159.txt3_2015041321292659391.txt3_20150414124528747462.txt3_20150414125110440425.txt3_20150414134437706174.txtI can list the files by issuing a command like this:ls -l | grep '20150413\|20150414' |awk '{print $NF}'But I am struggling to find a <= match.
Get files with a name containing a date value less than or equal to a given input date
linux;shell;grep
You can use awk and its string comparison operator.ls | awk '$0 < 3_20150415'In a variable:max=3_20150414 export maxls | LC_ALL=C awk '$0 <= ENVIRON[max] z'concatenating with z here makes sure that the comparison is a string comparison, and allows any time on that day since in the C locale, digits sort before z.