Skip to content

Instantly share code, notes, and snippets.

@greymd
Last active October 23, 2016 10:50
Show Gist options
  • Save greymd/48a7511015c70ac66bee63ff4eddf336 to your computer and use it in GitHub Desktop.
Save greymd/48a7511015c70ac66bee63ff4eddf336 to your computer and use it in GitHub Desktop.
markdownの[^なんとか]の形式を上から連番にするシェル芸
adjust_md_refs () {
local _tmp_file="/tmp/$$.adjust_md_refs"
cat "$1" | grep -oP '\[\^[^\[]*?\](?!:)' | while read s; do echo "$s" | awk '{print "s/"$1"/[^'$(cat /dev/urandom| LANG=C tr -dc 'A-Za-z0-9' | fold -w 10 | head -n 1)']/g"}' ;done | perl -pe 's/[\[\]]/\\$&/g' | sed -f - "$1" > "$_tmp_file"
cat "$_tmp_file" | grep -oP '\[\^[^\[]*?\](?!:)' | awk '{print "s/"$1"/[^"NR"]/g"}' | perl -pe 's/[\[\]]/\\$&/g' | sed -f - "$_tmp_file"
rm "$_tmp_file"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment