Description
Given a sorted data file,
each line consists of several fields separated by colons (':').
A block is consists of consecutive lines whose first fields are of the
same value.
What we want to do is appending
**********
Duplicate
*********
after every block.
|
| Raw Input
|
| Desired Output
| Monica:pc-s01.hq:2003/05/01:ME
Kelly:pc-x01.plant:2002/06/05:Linux
Kelly:pc-a01.hq:2003/12/25:XP
Qoo:mail.hq:2000/04/12:Linux
John:tester.plant:2004/09/01:XP
Johnson:mail.plant:2003/11/12:Linux
Johnson:x31.plant:2004/01/01:Linux
Johnson:x40.plant:2004/09/07:None
|
| Monica:pc-s01.hq:2003/05/01:ME
Kelly:pc-x01.plant:2002/06/05:Linux
Kelly:pc-a01.hq:2003/12/25:XP
*********
Duplicate
*********
Qoo:mail.hq:2000/04/12:Linux
John:tester.plant:2004/09/01:XP
Johnson:mail.plant:2003/11/12:Linux
Johnson:x31.plant:2004/01/01:Linux
Johnson:x40.plant:2004/09/07:None
*********
Duplicate
*********
|
|
Script and Comments
Script1 [ 1] p
[ 2] $!N
[ 3] /^\([^:]*:\).*\n\1/{h;D}
[ 4] x
[ 5] /./{
[ 6] i\
[ 7] =========\
[ 8] Duplicate\
[ 9] =========
[10] s/^.*//
[11] }
[12] x
[13] D
| |