Last active
January 18, 2019 20:21
-
-
Save ashiklom/a9275d60ebb94580c4b0 to your computer and use it in GitHub Desktop.
OneNote to 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
#!/bin/bash | |
# This is an example comment on this issue | |
# Get arguments | |
infile=${1} | |
outdir=${2-"output"} | |
mkdir -p $outdir | |
# Create scratchfile for modifying | |
scratchfile=$outdir/"scratch.md" | |
cp -rf $infile $scratchfile | |
# Find all lines that start with a date, formatted EXACTLY this way | |
IFS=$'\n' | |
matches=($(grep -nP "^(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), (January|February|March|April|May|June|July|August|September|October|November|December) \d{1,2}, \d{4}" $scratchfile)) | |
# Loop over indices in reverse | |
indices=( ${!matches[@]} ) | |
for ((i=${#indices[@]} - 1; i >=0; i--)); do | |
# Separate the line number and date from the full match string (% matches beginning, # matches end) | |
linenum=${matches[i]%:*} | |
echo $linenum | |
# Line of note title (2 lines above date) | |
titleline=$(($linenum-2)) | |
title=$(tail -n+$titleline $scratchfile | head -n1) | |
if date -d$title; then | |
title=$(date -d+$title +%Y-%m-%d) | |
else | |
linedate=${matches[i]#*:} | |
linedate=$(date -d+$linedate +%Y-%m-%d) | |
title=$linedate | |
fi | |
outfile=$outdir/${title}.wiki | |
## Get output file string and remove it from scratchfile | |
tail -n+$titleline $scratchfile >> $outfile | |
sed -i "$titleline,$ d" $scratchfile | |
## Format first line of output file as vimwiki title | |
sed -i -E '1 s/(.*)/= \1 =/g' $outfile | |
done | |
rm -rf $scratchfile | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment