1
0
Fork 0
This commit is contained in:
Arthur Khachaturov 2024-08-27 22:18:49 +03:00
parent 8d167995c7
commit 43c9688558
No known key found for this signature in database
GPG key ID: CAC2B7EB6DF45D55
6 changed files with 38 additions and 21 deletions

View file

@ -1,6 +1,7 @@
#!/bin/bash
: "${1:?Missing filename!}"
[ ! -f "$1" ] && { echo "Wrong filename!" >&2; exit 1; }
FILENAME="$(mktemp)"
@ -11,16 +12,18 @@ cleanup() {
trap 'cleanup' INT HUP TRAP
shift_header() {
read -r line < "$1"
if [[ "$line" = "# "* ]]; then
echo "---"
echo "title: ${line#"# "}"
echo "---"
tail -n +2 "$1"
else
cat "$1"
fi
local counter=1
while read -r line; do
(( counter+=1 ))
if [[ "$line" = "# "* ]]; then
echo "---"
echo "title: ${line#"# "}"
echo "---"
tail -n +"$counter" < "$1"
return
fi
done < "$1"
cat "$1"
}
main() {