It is possible to ignore some of the fields in an regex expression. The issue is that I have an output of a sorted files from an FTP server. The problem is that FTP does not list the year from the files that are 6 months or newer. So for example if I want to sort this 020319
and 100518
and I want to list the latest by date it will sort first 100518
, and that's not good.
FTP_FILES_LIST is a file with a bunch of files from an "ls" command from an FTP Site. I use "grep" to get only the files I'm interested in.
A="AT_20_10_REL_ARCA_"
more FTP_FILES_LIST | grep "$A[0-9][0-9][0-9][0-9][0-9][0-9].txt" | sort -k 9
-r-xr-xr-x 1 14 2000 34037013 Jan 17 00:45 AT_20_10_REL_ARCA_011719.txt
-r-xr-xr-x 1 14 2000 34036101 Jan 18 11:13 AT_20_10_REL_ARCA_011819.txt
-r-xr-xr-x 1 14 2000 34036564 Jan 25 01:09 AT_20_10_REL_ARCA_012519.txt
-r-xr-xr-x 1 14 2000 34041306 Feb 03 21:42 AT_20_10_REL_ARCA_020319.txt
-r-xr-xr-x 1 14 2000 34099207 Feb 08 03:15 AT_20_10_REL_ARCA_020819.txt
-r-xr-xr-x 1 14 2000 34099827 Feb 11 02:55 AT_20_10_REL_ARCA_021119.txt
-r-xr-xr-x 1 14 2000 34010091 Oct 05 00:42 AT_20_10_REL_ARCA_100518.txt
-r-xr-xr-x 1 14 2000 34025780 Nov 26 02:55 AT_20_10_REL_ARCA_112618.txt
-r-xr-xr-x 1 14 2000 34037370 Dec 19 22:10 AT_20_10_REL_ARCA_121918.txt
Using the "sed" doesn't sort as it should not sort as it should be. Here is the output:
more FTP_FILES_LIST | grep $A[0-9][0-9][0-9][0-9][0-9][0-9] | sed -E 's/^(..)(..)(..)/\3\1\2/' | sort | sed -E 's/^(..)(..)(..)/\2\3\1/'
-r-xr-xr-x 1 14 2000 34010091 Oct 05 00:42 AT_20_10_REL_ARCA_100518.txt
-r-xr-xr-x 1 14 2000 34025780 Nov 26 02:55 AT_20_10_REL_ARCA_112618.txt
-r-xr-xr-x 1 14 2000 34036101 Jan 18 11:13 AT_20_10_REL_ARCA_011819.txt
-r-xr-xr-x 1 14 2000 34036564 Jan 25 01:09 AT_20_10_REL_ARCA_012519.txt
-r-xr-xr-x 1 14 2000 34037013 Jan 17 00:45 AT_20_10_REL_ARCA_011719.txt
-r-xr-xr-x 1 14 2000 34037370 Dec 19 22:10 AT_20_10_REL_ARCA_121918.txt -> Wrong sort!
-r-xr-xr-x 1 14 2000 34041306 Feb 03 21:42 AT_20_10_REL_ARCA_020319.txt
-r-xr-xr-x 1 14 2000 34099207 Feb 08 03:15 AT_20_10_REL_ARCA_020819.txt
-r-xr-xr-x 1 14 2000 34099827 Feb 11 02:55 AT_20_10_REL_ARCA_021119.txt
It is possible to group the dates in pairs with sed and/or regex? I have six [0-9]; one per each date digit. What about if its possibe to us regex or sed to sort those in pairs? like for example 100518; to sort 10 then 05 then 18.
Using more FTP_FILES_LIST | grep "$A[0-9][0-9][0-9][0-9][0-9][9].txt" | sort -k 9
is a workaround but I'm losing all files from 2018. I added a picture of the output because the format changes here!
grep
commands you're using. (For example, using the firstgrep
in your question against the set of files you've shown returns no results.) Please go back and edit your question so that they match.sort -k1.5
- I don't see how regular expressions need to be involved here at allls
command; is that true?