Last active
October 27, 2017 03:58
-
-
Save masashinakata/93a3c77045a5aa0c59f31782ea8ae71c to your computer and use it in GitHub Desktop.
unpack.sh - Snippet that splits into sample files and answer files.
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/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