Skip to content

Instantly share code, notes, and snippets.

@domargan
Created August 8, 2020 00:42
Show Gist options
  • Save domargan/5141965cd19e37047bfd34ddc4c4ab53 to your computer and use it in GitHub Desktop.
Save domargan/5141965cd19e37047bfd34ddc4c4ab53 to your computer and use it in GitHub Desktop.
Sorting markdown tables by column
#!/bin/bash
# Credit: https://christiantietze.de/posts/2017/05/sort-markdown-tables-shell/
# First argument is a path to table file in markdown format
# Second argument is the key column+1 to sort by
(head -n 2 $1 && tail -n +3 table.md | sort --field-separator=\| --key=$2) > sorted_table.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment