I have an output file that looks like this:
HEADER 1:
server1 server2 server3
server4 server5 server6
server7 server8 server9
HEADER 2:
HEADER 1:
server10 s
Using sed:
sed '/HEADER 1/{n;:l N;/HEADER 2/b; s/\n//; bl}' input
n
skips/prints the current line (HEADER 1), clears buffer l
is a label for looping (goto label)N
adds (appends) lines to buffer (preserving newlines)/HEADER 2/b
, where b is branch (without the label, it is break), break out when HEADER2 is seens/\n//
removes the newlines in the bufferbl
jumps back to label l
This shows how it could be done using awk
You can download Gawk
for Windows
awk '/HEADER/ {printf "\n%s\n",$0;next} {printf "%s ",$0}' file
HEADER 1:
server1 server2 server3 server4 server5 server6 server7 server8 server9
HEADER 2:
HEADER 1:
server10 server11 server12 server13 server14 server15 server16 server17 server18
HEADER 2: