Generate an HTML table of files with their sizes and SHA-256 hashes #

The downloads index was previously generated with QuickHash GUI. I decided to cobble something together in Bash that better suited my needs:

$ gfind . -name "[!.]*" -type f -printf '%f %s ' -exec shasum -a 256 {} \; | awk -F ' ' '{ print $1, "| " $2, "| " $3 }' | sort -f | sed 's/_/\\_/g' | (printf "Filename | Bytes| SHA-256\n--- | --- | ---\n" && cat) | markdown2.py --extras tables > output.html
  1. gfind . -name "[!.]*" -type f
    Find non-hidden files,

  2. -printf '%f %s '
    print their filenames and sizes,

  3. -exec shasum -a 256 {} \;
    and generate SHA-256 hashes for them.

  4. awk '{ print $1, "| " $2, "| " $3 }'
    Print the first 3 fields from gfind's output, separating them with vertical bars (necessary for the markdown table).

  5. sort -f
    Sort the resultant list alphabetically, ignoring case.

  6. sed 's/_/\\_/g'
    Find underscores and prepend backslashes to them so that they are not interpreted as italics when converting markdown to HTML.

  7. (printf "Filename | Bytes| SHA-256\n--- | --- | ---\n" && cat)
    Prepend header row (with the minimum number of dashes and vertical bars for the markdown table) to output.

  8. markdown2.py --extras tables
    Convert the markdown table to HTML

  9. > table.html
    and save as "output.html" in the current directory.

Notes:

/nix | Mar 24, 2019


Subscribe or visit the archives.