0

I take notes using markdown, and save them in the following structure

$NOTESDIR
- preface.md
- styling.tex
+ YR1
    + sem1
        - "LinAlgDat - Transformations and matrices.md"
    + sem2
        - "PoP - something fancy.md"
+ YR2
    + sem3
    + ...
+ YR3
    + ...
    + sem6

And I'm working on a script to compile either semesters to pdfs, or entire years to pdfs using pandoc

pandoc --toc -o "${1}.pdf" "$NOTESDIR/preface.md" $2 &&
echo "Compiling ${1}.pdf"

Now, to feed all the files names to the command, I have to sort them. I want to sort them either by course (LinAlgDat, PoP) or by date (all note files contains a line with "> Date: DD-MM-YY". I can easily use "ack" to get all the files, but I haven't found a solution for sorting the output of ack.

  • Your format is already pretty close to YAML; I suggest switching to that, then using a language with a YAML parser to process the data. – chepner Jul 16 '16 at 15:18
  • Is there a single `.md` .file in each `semX` directory? – tripleee Jul 16 '16 at 16:09
  • there are multiple `.md` in each semX dir, and usually multiple courses aswell. –  Jul 16 '16 at 16:33
  • 1
    too bad you didn't name your files with a naturally sorting format like `YYYY-MM-DD`. So you'll have to save your filenames to a text file, then use `sort -k3 -k2 -k1` on that file (or similar, `man sort` and look here at `sort` Qs for advanced usage of `*k*eys`) and use that to drive your processing. Good luck. – shellter Jul 16 '16 at 20:00

1 Answers1

1

The solution I found was to ack all the files that contained the string, and then prepend the dates to the string containing the file name. Then sort the filenames, and use sed to grab the order of the file names.