From 0ff2299c083319d94056ae78c4ba8a973098d3c9 Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Sun, 17 Dec 2017 00:52:04 +0100 Subject: add shell script variant of pipe mode --- rnl.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100755 rnl.sh diff --git a/rnl.sh b/rnl.sh new file mode 100755 index 0000000..d9d70cd --- /dev/null +++ b/rnl.sh @@ -0,0 +1,18 @@ +#!/bin/sh +# rnl - remove final newlines + +tr1='\012 ' +tr2=' \012' +pat='$s/ *$/ /' + +while getopts 0aso opt; do + case "$opt" in + 0) tr1='\0 '; tr2=' \0';; + a) pat='$s/ *$//';; + s) pat='$s/ *$/ /';; + o) pat='$s/ $//';; + '?') exit 1;; + esac +done + +tr "$tr1" "$tr2" | sed "$pat" | tr "$tr2" "$tr1" -- cgit 1.4.1