Description
Given a data file,
- a KEYWORD record is followed by a DESC record.
- a KEYWORD/DESC record may consists of several lines,
in this case, we want to join these lines to one.
- a DESC record is followed by a blank line or end of the file.
|
| Raw Input
| BOOK: Sed & Awk
KEYWORD: sed,
awk, script language,
regular expressions
DESC: good book
on string processing
with regular expressions.
BOOK: Mastering Regular Expressions
KEYWORD: perl,
script language,
regular expressions
DESC: a concrete book
on string processing, several languages
are introduced.
|
|
| Desired Output
| BOOK: Sed & Awk
KEYWORD: sed, awk, script language, regular expressions
DESC: good book on string processing with regular expressions.
BOOK: Mastering Regular Expressions
KEYWORD: perl, script language, regular expressions
DESC: a concrete book on string processing, several languages are introduced.
|
|
Script and Comments
Script1 [ 1] /^KEYWORD/!b
[ 2] :loop0
[ 3] N
[ 4] /\nDESC/!b loop0
[ 5] h
[ 6] s/\n[^\n]*$//
[ 7] s/\n/ /g
[ 8] p
[ 9] G
[10] s/^.*\n//
[11] :loop1
[12] $!{
[13] N
[14] /\n$/!b loop1
[15] }
[16] s/\n\(.\)/ \1/g
| |