Description
The datafile contains several blocks where each one contains:
- A starting line consisting of a tag, followed by a space,
then the word 'start'.
- Several data lines.
Each data line is indented by spaces of length equal to the tag,
followed by a space, then the data itself.
- An ending line consisting of a tag, followed by a space,
then the word 'end'.
What we want is to replace the indented spaces in every data line
with the tag of that block.
|
| Raw Input
|
| Desired Output
| MIS start
data1
data2
MIS end
ACCT start
data1
data2
ACCT end
|
| MIS start
MIS data1
MIS data2
MIS end
ACCT start
ACCT data1
ACCT data2
ACCT end
|
|
Script and Comments
Script1 [sed] [ 1] /^\([^ ]*\) start/{
[ 2] p
[ 3] s/ .*//
[ 4] h
[ 5] d
[ 6] }
[ 7] /^ *[^ ]/!b
[ 8] G
[ 9] s/^\(.*\)\n\(.*\)/\2\n\2\n\1/
[10] :loop
[11] s/[^\n]\n /\n/
[12] t loop
[13] s/\n//g
| |
|