From: mirabilos Date: Sat, 4 Jun 2016 03:19:59 +0000 (+0000) Subject: some script I wrote for a quick hack X-Git-Url: https://evolvis.org/plugins/scmgit/cgi-bin/gitweb.cgi?p=shellsnippets%2Fshellsnippets.git;a=commitdiff_plain;h=5c7bd7d94b8181d09949b73c7a69cbfba28457c0 some script I wrote for a quick hack --- diff --git a/mksh/mergelines b/mksh/mergelines new file mode 100644 index 0000000..30ef39b --- /dev/null +++ b/mksh/mergelines @@ -0,0 +1,40 @@ +#!/bin/mksh +# $MirOS: src/share/misc/licence.template,v 1.28 2008/11/14 15:33:44 tg Rel $ +#- +# Copyright © 2016 +# mirabilos +# +# Provided that these terms and disclaimer and all copyright notices +# are retained or reproduced in an accompanying document, permission +# is granted to deal in this work without restriction, including un‐ +# limited rights to use, publicly perform, distribute, sell, modify, +# merge, give away, or sublicence. +# +# This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to +# the utmost extent permitted by applicable law, neither express nor +# implied; without malicious intent or gross negligence. In no event +# may a licensor, author or contributor be held liable for indirect, +# direct, other damage, loss, or other issues arising in any way out +# of dealing in the work, even if advised of the possibility of such +# damage or existence of a defect, except proven that it results out +# of said person’s immediate fault when using the work as intended. + +[[ -n $1 ]] && IFS=$1 + +l1= +l2= +lp=0 +while read -r n1 n2; do + if [[ $n1 = $l1 ]]; then + l2+=$IFS$n2 + lp=1 + continue + fi + if (( lp )); then + print -r -- "$l1$IFS$l2" + lp=0 + fi + l1=$n1 + l2=$n2 +done +(( lp )) && print -r -- "$l1$IFS$l2"