I'm
struggling with a Grep Find/Replace action to apply to a file with
sorted lines, each having three units separated by tabs:
first1
second11 third111
first1
second11 third112
first1
second11 third113
first1
second11 third114
first1
second11 third115
first2
second21 third211
first2
second22 third221
first2
second23 third231
first3
second31 third311
first3
second31 third312
first3
second31 third313
first3
second31 third314
first3
second32 third321
first4
second41 third411
first4
second41 third412
first4
second42 third421
first4
second42 third422
first5
second51 third511
first5
second52 third521
first5
second52 third522
first5
second52 third523
first5
second53 third531
...
Now I need to insert an underscore at the beginning
of each line IF the "first" and "second" fields are identical to the
respective fields in its previous line. The result should be this:
first1
second11 third111
_first1
second11 third112
_first1
second11 third113
_first1
second11 third114
_first1
second11 third115
first2
second21 third211
first2
second22 third221
first2
second23 third231
first3
second31 third311
_first3
second31 third312
_first3
second31 third313
_first3
second31 third314
first3
second32 third321
first4
second41 third411
_first4
second41 third412
first4
second42 third421
_first4
second42 third422
first5
second51 third511
first5
second52 third521
_first5
second52 third522
_first5
second52 third523
first5
second53 third531
...
I
presume this could be achieved by using positive look-behind assertion,
but all my attempts have failed so far.
Any help greatly is
appreciated!
samar