From 784f90729b46f5ce9099d7a34b1d4273f04a3c99 Mon Sep 17 00:00:00 2001 From: Akemi Izuko Date: Tue, 7 Nov 2023 20:21:40 -0700 Subject: [PATCH] Add tailing-newline-removal script --- bin/remove_last_line.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100755 bin/remove_last_line.sh diff --git a/bin/remove_last_line.sh b/bin/remove_last_line.sh new file mode 100755 index 0000000..f360b3c --- /dev/null +++ b/bin/remove_last_line.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +if [[ ! -f "$1" ]]; then + cat < +HELP + + exit 1 +fi + +declare -r tmp="$(mktemp)" + +if [[ "$(tail -c 1 "$1" | wc -l)" = 1 ]]; then + head -c -1 "$1" > "$tmp" + mv -f "$tmp" "$1" +fi