From 861dfd0bc5fde111e2bc90f624b1e8a8db46a284 Mon Sep 17 00:00:00 2001 From: Alfred Melch Date: Sun, 2 Jan 2022 19:20:10 +0100 Subject: [PATCH] Fix input fetching script Retain blank lines in code examples. The script removed all blank lines from code examples. This is not always desired as there might be important blank lines inside the code block. The change targets specifically the starting and ending blank line of the examples and removes them. --- lib/aoc.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/aoc.sh b/lib/aoc.sh index f546a2b..3c84954 100755 --- a/lib/aoc.sh +++ b/lib/aoc.sh @@ -26,8 +26,11 @@ echo "Extracting example code blocks..." # extract example code blocks cat README.md | sed -n '/\[code\]/,/\[\/code\]/p' | # extract code blocks - sed '/^\s*$/d' | # remove empty lines - sed '/^\[\/code\]/d' | # remove closing bracket + 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) + 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."