在文本文件中,如何删除其紧接行的所有行子集?

问题描述 投票:0回答:1

在文本文件中,我需要删除与下一行完全相同的行。请参见下面的示例。

输入:

I like
I like apples
I like apples and oranges
more
more everyday
more everyday
more everyday the more
more everyday the more I play
I
I like

输出:

I like apples and oranges
more everyday the more I play
I like
linux command-line-interface
1个回答
0
投票

一种方法:

$ perl -lne 'print $last unless /^\Q$last/;  $last = $_;
             END { print $last }' input.txt
I like apples and oranges
more everyday the more I play
I like
© www.soinside.com 2019 - 2024. All rights reserved.