Last active
October 23, 2016 10:50
-
-
Save greymd/48a7511015c70ac66bee63ff4eddf336 to your computer and use it in GitHub Desktop.
markdownの[^なんとか]の形式を上から連番にするシェル芸
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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