0

i have to take the latest file from zip in bash. OK if they were with different timestamp created :) files are like:

  • file_9283208320382 DATE HOUR-MINUTE-SECCOND AM/PM.csv
  • file_1283208320382 DATE HOUR-MINUTE-SECCOND AM/PM.csv

all are created in same second in the archive - for example: 12:22

is there any way to get this without taking the last string from the file as an timestamp and compare in a loop each of them.

thank you !

Vasilev
  • 87
  • 1
  • 9
  • https://stackoverflow.com/questions/5885934/bash-function-to-find-newest-file-matching-pattern – stickabee Nov 18 '19 at 14:09
  • No. Extracting the timestamps from the filenames requires a loop. Otherwise, how will the program know what the values of the timestamps are? – jhnc Nov 18 '19 at 19:44
  • Please post sample listing of the ZIP file. The question is not clear. Are you looking for the file with the latest modification time, or the file with the largest timestamp in the file name – dash-o Nov 18 '19 at 21:25

1 Answers1

0

thanks for the reply. this is one sample:

  • -rw---- 2.0 fat 10764 bl 1922 defN 19-Nov-15 20:45 filetext_121212_2019-11-15 03-40-45 PM.txt
  • -rw---- 2.0 fat 10757 bl 1919 defN 19-Nov-15 20:45 filetext_232323_2019-11-15 01-40-38 PM.txt
  • -rw---- 2.0 fat 10753 bl 1925 defN 19-Nov-15 20:45 filetext_242424_2019-11-15 12-11-13 PM.txt
  • -rw---- 2.0 fat 10757 bl 1922 defN 19-Nov-15 20:45 filetext_143141_2019-11-15 04-40-30 PM.txt
  • -rw---- 2.0 fat 10757 bl 1928 defN 19-Nov-15 20:45 filetext_111111_2019-11-15 09-40-53 AM.txt
  • -rw---- 2.0 fat 10765 bl 1930 defN 19-Nov-15 20:45 filetext_120121_2019-11-15 06-10-34 PM.txt
  • -rw---- 2.0 fat 10756 bl 1925 defN 19-Nov-15 20:45 filetext_111222_2019-11-15 10-42-43 AM.txt
  • -rw---- 2.0 fat 10686 bl 1929 defN 19-Nov-15 20:45 filetext_222111_2019-11-15 02-40-46 PM.txt

the problem is the timestamp of the files - same - 19-Nov-15 20:45. the timestamp in the filename - 03-40-45 PM. so my idea was to take this string and to transform it to timestamp. then in a loop - compare if there is bigger.. if there is clever way, please let me know :)

Vasilev
  • 87
  • 1
  • 9