0

I have a folder containing hundreds of files with filenames such as month-day-time.txt They follow a pattern of 1 file for every 10th minute of the hour, as in the example (here the minutes differentiate the files):

06-03-01h10.txt

06-03-01h20.txt

06-03-01h30.txt

What Terminal command and syntax should I use to get a list of filenames (or files) that are missing thus breaking the filename pattern?

Example: if 06-03-01h40.txt doesn't exist, I'd like it to appear in the returned list of filenames or files.

7
  • My preference would be to pipe ls to a file, and use regex to search the file. Jun 3, 2015 at 15:21
  • @DrMoishePippik Even then, a regex to search for a numeric pattern that involves arithmetic isn't normal regex functionality
    – barlop
    Jun 3, 2015 at 15:59
  • AT Ramhound what do you expect him to try. what would you try (aside from coding a program to do it - which he might not be able to do) ? (And even then, it's a complex problem, just saying 'i tried a for loop' won't he that helpful and at that level is more Stackoverflow). it's not like there are obvious things to just try.
    – barlop
    Jun 3, 2015 at 16:00
  • In a programming language, I would generate the list of expected filenames in a loop, check if the file exists, and list any missing, though i do not know how to do so from terminal. Jun 3, 2015 at 16:03
  • similar to Moishe Pippik, i'd use some programming language or other, but i'd do a stage 1, of scanning through hte list of filesnames of existing files, and then see if the filename before and after it matcbes the pattern, if it does then mark that filename with the text "yeah" to the right of it. otherwise mark "nope" to the right of it. Then examine the output and think about adjusting stage 1 or think about your stage 2. along the lines of outputting all the files marked "yeah" up to one marked "nope".
    – barlop
    Jun 3, 2015 at 16:09

2 Answers 2

0

Using {00..05} in bash, tries the command with 00 then 01, 02 etc.

ls {01..12}-{01..31}-{01..24}h{00,10,20,30,40,50}.txt 1>/dev/null

Will give you errors only for the files that do not exist, edit the code to exclude months you don't have etc.

0
0

I'd pipe it to a file, load it into Excel, generate a list of expected file names in the next column then use a VLOOKUP to see which ones in the expected list are not in the actual list.

2
  • Though this isn't a solution using Terminal, thinking about it I believe the list of 'expected' filenames wouldn't work after the 1st filename that breaks the pattern occurs. Then the following filenames wouldn't be a match to the column of 'expected' filenames.
    – Chris
    Jun 3, 2015 at 17:16
  • @Chris No, it doesn't work that way. It's not expecting a 1-1 match. VLOOKUP can be used to just say whether the value EXISTS in the other list - so you'd end-up with a list of non-matching entries. But if you are dead-set on using terminal then I agree this answer is useless.
    – Lefty
    Jun 3, 2015 at 17:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .