about summary refs log tree commit diff
diff options
context:
space:
mode:
-rwxr-xr-xrnl.sh18
1 files changed, 18 insertions, 0 deletions
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"