Trying to turn
a: 1, 2, 3
a: a, b, v
b: 5, 6, 7
b: 10, 1543, 1345
b: e, fe, sdf
cd: asdf, asdfas dfasdfa,asdfasdfa,afdsfa sdf
e1: asdfas, dafasd, adsf, asdfasd
e1: 1, 3, 2
e1: 9, 8, 7, 6
into
a: 1, 2, 3
a, b, v
b: 5, 6, 7
10, 1543, 1345
e, fe, sdf
cd: asdf, asdfas dfasdfa,asdfasdfa,afdsfa sdf
e1: asdfas, dafasd, adsf, asdfasd
1, 3, 2
9, 8, 7, 6
So, the lines are sorted. If consecutive lines start with the same sequence of characters up to / including some separator (here the colon (and the blank following it)), only the first instance should be preserved - as should be the remainder of all lines. There could be up to about a dozen (and a half) lines starting with the identical sequence of characters. The input holds about 4,500 lines…
Tried in TextWrangler.
Whilst the search pattern
^([[:alnum:]]+): (.+)\r((\1:) (.+)\r)*
matches correctly, neither the replacement
\1:\t\2\r\t\3\r
nor
\1:\t\2\r\t\4\r
gets me anywhere close to what I'm looking for.
The search pattern
^(.+): (.+)\r((?<=\1:) (.+)\r)*
is rejected for the lookbehind not being fixed length. - Not sure, it's going into the right direction anyway, though.
Looking at How to merge lines that start with the same items in a text file I wonder, whether there is an elegant (say: one search pattern, one replacement, run once) solution at all.
On the other hand, I might just not be able to come up with the right question to search the net for. If you know better, please, point me into the right direction.
Keeping the remainder of the rows aligned is, of course, sugar on the cake…
Thank you for your time.
(?<=(\w\w:)|(\w:))\h(.*\R?)\1?\2?
replace with\t\3
. See test at regex101. Max prefix length is 2, further max length can be added. Unclear if you want to have a tab for each line or replace each character of the prefix with one space. – Lannylanolin(?<=(\w\w:)|(\w:))\s(.*\n?)\1?\2?
it does the job as wanted. You might want to turn that into an answer. If you do, please, expand on the mechanics. – Retool\G
is not available. You might want to double check: TextWrangler User Manual. – Retool