The requirements are as follows:
That is to say, row n is removed, and n satisfies the condition that the initials of row n, row N-1, and row N+1 are the same (the first row and the last row are not removed).
Can I use the vi replacement command or shell to fulfill this requirement? Just give me a hint, thank you. (I have already implemented it in C++, and now I just want to know if it can be implemented in regular expressions.)
Regularity of vim
Explain it in three paragraphs.
Match the first row, the outer grouping is used for reverse reference when replacing, and the inner grouping is used for later judgment.
Match the line (1 or more lines) beginning with the first letter of the following previous line.
Match a line that begins with the first letter of the first line.
Finally \1\5 Replace all the rows matched above with the first row and the last row, that is, delete the middle row.
Note: The initial \v switch is to perl regular mode, so brackets and plus signs do not need to be escaped.
BTW is the most convenient text processing job to complete with perl scripts. The advantage of vi is visual debugging, but GG is used when large files are encountered.