From f885b70c9e82d1ccc70a8566893382fc033e66ef Mon Sep 17 00:00:00 2001 From: Alfred Melch Date: Wed, 5 Jan 2022 15:28:21 +0100 Subject: [PATCH] Fix example extraction Assumtion was that the first and last lines of examples are always blank. In 2021/06 the example is only one line. It has no blank line at the end so the example was deleted by the script. Changed: The script will now check if the line is actually blank before deleting it. Requires that the indentation is removed beforehand. --- lib/aoc.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/aoc.sh b/lib/aoc.sh index 3c84954..3ae3e19 100755 --- a/lib/aoc.sh +++ b/lib/aoc.sh @@ -26,12 +26,12 @@ echo "Extracting example code blocks..." # extract example code blocks cat README.md | sed -n '/\[code\]/,/\[\/code\]/p' | # extract code blocks - sed '/\[code\]/{n;d}' | # remove (blank) lines after opening bracket + sed 's/^ //' | # remove indentation + sed '/\[code\]/{n;/^$/d}' | # remove blank lines after opening bracket tac | # reverse line order - sed '/\[\/code\]/{n;d}' | # remove (blank) lines after closing brackets (preceding blank lines in normal order) + sed '/\[\/code\]/{n;/^$/d}' | # remove blank lines after closing brackets (preceding blank lines in normal order) tac | # reverse line order again sed '/^\[\/code\]/d' | # remove closing brackets - sed 's/^ //' | # remove indentation csplit - --suppress-matched --elide-empty-files --prefix='input/example' --suffix='%d' '/\[code\]/' '{*}' echo "done."