Linux 使用sed或其他方法删除每隔一定行数出现的重复行

Linux 使用sed或其他方法删除每隔一定行数出现的重复行,linux,sed,Linux,Sed,我有一个巨大的文件,我想删除重复的行,只发生每3行。 是否可以使用sed或任何类似命令 我的文件如下所示: this is text 1234 1234 this is another text 5678 5678 第二个数字是第一个数字的副本,我想删除文件中每3行的第二个数字(第三行)。我之所以不使用较少的filename | uniq,是因为数字可能会在文件中重复(超出3行范围),我不希望删除它们 谢谢这能解决你的问题吗 $ awk 'NR%3!=0' input this is

我有一个巨大的文件,我想删除重复的行,只发生每3行。 是否可以使用sed或任何类似命令

我的文件如下所示:

this is text

1234

1234

this is another text

5678

5678
第二个数字是第一个数字的副本,我想删除文件中每3行的第二个数字(第三行)。我之所以不使用较少的filename | uniq,是因为数字可能会在文件中重复(超出3行范围),我不希望删除它们


谢谢这能解决你的问题吗

$ awk 'NR%3!=0' input
this is text


1234
this is another text


5678
使用sed:

$ sed '0~3d' input
this is text


1234
this is another text


5678
Perl:


但是,再说一遍,我可能会问这个问题……

这能解决你的问题吗

$ awk 'NR%3!=0' input
this is text


1234
this is another text


5678
使用sed:

$ sed '0~3d' input
this is text


1234
this is another text


5678
Perl:


但是,再说一遍,我可能会问这个问题……

这能解决你的问题吗

$ awk 'NR%3!=0' input
this is text


1234
this is another text


5678
使用sed:

$ sed '0~3d' input
this is text


1234
this is another text


5678
Perl:


但是,再说一遍,我可能会问这个问题……

这能解决你的问题吗

$ awk 'NR%3!=0' input
this is text


1234
this is another text


5678
使用sed:

$ sed '0~3d' input
this is text


1234
this is another text


5678
Perl:


但是,再一次,我可能遗漏了这个问题…

uniq实用程序只过滤掉相邻的行(您的输入是否真的在每行之间有一个空行?)。否则,可以使用:

this is text
1234
1234
this is another text
1234
1234
uniq input.txt
给出:

this is text
1234
this is another text
1234

uniq
实用程序只过滤掉相邻的行(您的输入在每行之间真的有空行吗?)。否则,可以使用:

this is text
1234
1234
this is another text
1234
1234
uniq input.txt
给出:

this is text
1234
this is another text
1234

uniq
实用程序只过滤掉相邻的行(您的输入在每行之间真的有空行吗?)。否则,可以使用:

this is text
1234
1234
this is another text
1234
1234
uniq input.txt
给出:

this is text
1234
this is another text
1234

uniq
实用程序只过滤掉相邻的行(您的输入在每行之间真的有空行吗?)。否则,可以使用:

this is text
1234
1234
this is another text
1234
1234
uniq input.txt
给出:

this is text
1234
this is another text
1234

对您的输入内容和输出内容进行假设:

awk 'NR%3 == 2 {val=$0} NR%3 == 0 && $0 == val {next} 1' <<END
this is text
1234
1234
this is another text
5678
5678
foo
bar
qux
END

对您的输入内容和输出内容进行假设:

awk 'NR%3 == 2 {val=$0} NR%3 == 0 && $0 == val {next} 1' <<END
this is text
1234
1234
this is another text
5678
5678
foo
bar
qux
END

对您的输入内容和输出内容进行假设:

awk 'NR%3 == 2 {val=$0} NR%3 == 0 && $0 == val {next} 1' <<END
this is text
1234
1234
this is another text
5678
5678
foo
bar
qux
END

对您的输入内容和输出内容进行假设:

awk 'NR%3 == 2 {val=$0} NR%3 == 0 && $0 == val {next} 1' <<END
this is text
1234
1234
this is another text
5678
5678
foo
bar
qux
END
这可能适用于您(GNU-sed):

打印三行中的第一行,如果第三行与第二行重复,则删除第三行。

这可能适用于您(GNU-sed):

打印三行中的第一行,如果第三行与第二行重复,则删除第三行。

这可能适用于您(GNU-sed):

打印三行中的第一行,如果第三行与第二行重复,则删除第三行。

这可能适用于您(GNU-sed):


打印三行中的第一行,如果第三行与第二行重复,则删除第三行。

您的数据到底是什么样子的?是的;请用一些示例输入和所需输出更新您的问题;这样就更容易回答:-)你的数据到底是什么样子的?是的;请用一些示例输入和所需输出更新您的问题;这样就更容易回答:-)你的数据到底是什么样子的?是的;请用一些示例输入和所需输出更新您的问题;这样就更容易回答:-)你的数据到底是什么样子的?是的;请用一些示例输入和所需输出更新您的问题;这样就更容易回答:-)