Description
- The file is assumed sorted.
- The tag of a line is separated with other part of that line by a space.
What we want is joining all lines of the same tag together,
remove all tags then print.
In the following, three scripts are provided.
The first is tedious but straightforward,
the second is an improved version, and the third is the neat one.
|
| Raw Input
| 7254 romans@abc.net
7254 stack@bcd.org
7254 giant@ab.cd.com
70613 mega@true.edu.tw
70613 meggy@false.com
70613 antims@msgotohell.cx
70613 ramma@comics.co.jp
enc gary@enc.com
enc devin@enc.com
enc roy@enc.com
|
|
| Desired Output
| romans@abc.net stack@bcd.org giant@ab.cd.com
mega@true.edu.tw meggy@false.com antims@msgotohell.cx ramma@comics.co.jp
gary@enc.com devin@enc.com roy@enc.com
|
|
Script and Comments
Script1 [ 1] :loop
[ 2] $!{
[ 3] N
[ 4] /^\([^ ]* \).*\n\1/{
[ 5] s/\n[^ ]*//
[ 6] b loop
[ 7] }
[ 8] s/^[^ ]* //
[ 9] P
[10] D
[11] }
[12] s/^[^ ]* //
|
Script2 [ 1] :loop
[ 2] $!{
[ 3] N
[ 4] s/^\(\([^ ]* \).*\)\n\2/\1 /
[ 5] t loop
[ 6] s/^[^ ]* //
[ 7] P
[ 8] D
[ 9] }
[10] s/^[^ ]* //
| |
Script3 [ 1] :loop
[ 2] $!N
[ 3] s/^\(\([^ ]* \).*\)\n\2/\1 /
[ 4] t loop
[ 5] s/^[^ ]* //
[ 6] P
[ 7] D
| |
|