Description
- Given a datafile containing even number of lines:
- every line with odd line number is a tag;
- others are data lines.
- Every tag line is followed by an associated data line.
- What we want is
- splitting every data line to several lines by
inserting a newline char between every two adjacent characters;
- then prepend the associated tag to every lines resulting from splitting.
- Two scripts are provided where the first one much more readable than the second.
|
| Raw Input
|
| Desired Output
| 12
ABC
3456
DEFGH
|
| 12A
12B
12C
3456D
3456E
3456F
3456G
3456H
|
|
Script and Comments
Script1 [ 1] N
[ 2] :loop
[ 3] s/^\(.*\)\n\(.\)/\1\2\n\1\n/
[ 4] P
[ 5] s/^[^\n]*\n//
[ 6] /\n$/!b loop
[ 7] d
| |
Script2 [ 1] /\n/!N
[ 2] s/^\(.*\)\n\(.\)/\1\2\n\1\n/
[ 3] P
[ 4] /\n$/!D
[ 5] d
| |