Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
unpack.sh - Snippet that splits into sample files and answer files.
#!/bin/sh
i=1
bodyname="sample"
test -f "$bodyname$i.txt" && rm -f "$bodyname$i.txt"
test -f "$1" && exec <"$1"
sed -ne '
s/^ *$//
H
$ {
g
s/^\n*//g
s/\n*$//g
s/\(\n\n\)\n*/\1/g
p
}
' | while read l; do
if ! echo "$l" | grep '^ *$' > /dev/null; then
echo $l >> "$bodyname$i.txt"
else
if [ "$bodyname" == "sample" ]; then
bodyname="answer"
else
bodyname="sample"
i=`expr $i + 1`
fi
test -f "$bodyname$i.txt" && rm -f "$bodyname$i.txt"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment