#!/bin/sh #Join SPECIAL LINES (regexp R2) to prior REGULAR line (regrexp R1) #Assume that file starts with REGULAR line R1=$1 R2=$2 gsed -n ' 1{/'"$R1"'/!q #first line must be regular. if special, quit h #populate the hold space with first line b} #fall to bottom to initiate next read /'"$1"'/{ #new line is REGULAR x;s/\n//g;p; #print line in hold (after removing \n, if any) #current line is now in hold ${x;p} #special treatment if current line is last line b } /'"$R2"'/{ #new line is SPECIAL H #append current line to hold space ${x;s/\n//g;p} #special treatment if current line is last line } '