anki-decks/fromtext.sh

22 lines
526 B
Bash
Executable file

#!/bin/sh
SEP='\t'
COLUMNS='4 5'
main() {
while read -r line; do
filename=
i=0
for c in $COLUMNS; do
f="$(echo "$line" | awk -F$SEP "{print \$$c}")"
[ -z "$f" ] && continue
if [ "$filename" = '' ]; then
filename="$(echo "$f" | tr '[:upper:]' '[:lower:]' | sed -E -e 's/ /-/g' -e 's/[^a-z0-9-]//g' -n -e 's/^(.{0,128}).*$/\1/p')"
fi
echo "$f" > "$filename.$i.md"
i=$((i+1))
done
done
}
main "$@"