#!/usr/bin/env bash if [[ -z "${1}" ]]; then input=index.md output=../b/00blogdex.html headOut=blogdexHead.txt echo 'blogdex' else input=index2.md; output=../im/00imdex.html; headOut=imdexHead.txt;echo imdex fi [[ -f $input && -f $headOut ]] || exit 1; #[ -f $output ] && mv $output ."${output%%.*}"-old.html; # https://stackoverflow.com/questions/2664740/extract-file-basename-without-path-and-extension-in-bash oldoutput=$(echo "${output%/*}/.$(basename $output .html)-old.html") [ -f $output ] && mv $output "$oldoutput" sed -i "s;]\\\;\](;g; s;\\\;.htm\);g" $input # replace ]\ and \ to () sed -i 's/[[:blank:]]*$//' $input # each line remove blank end sed -i 's/$/ /' $input # add double space at end markdown_py $input > $output; #prepend $headOut except last 3 line to $output sed -i -e "1 e head -n -4 $headOut" $output #or '1 e cat $headOut|head -n -3' #prepend line to 3 headers tail -4 $headOut >> $output exit 0;