Add tailing-newline-removal script
This commit is contained in:
parent
d9e00d5e63
commit
ad005f402b
1 changed files with 16 additions and 0 deletions
16
bin/remove_last_line.sh
Executable file
16
bin/remove_last_line.sh
Executable file
|
@ -0,0 +1,16 @@
|
|||
#!/usr/bin/env bash
|
||||
if [[ ! -f "$1" ]]; then
|
||||
cat <<HELP
|
||||
Removes the tailing new line character in a file
|
||||
$(basename $0) <file>
|
||||
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
|
Loading…
Reference in a new issue