Bash awk每N个匹配行打印一次,所有行不匹配

Bash awk每N个匹配行打印一次,所有行不匹配,bash,shell,awk,Bash,Shell,Awk,我知道如何打印第n行和第n个匹配行,但不知道如何打印第n个匹配行和所有行,而不是数学 输入示例: Something else 1 Downloading: file1 1% Downloading: file1 10% Something else 2 Downloading: file1 30% Something else 3 Downloading: file1 40% Downloading: file2 50% Downloading: file1 60% Downloading:

我知道如何打印第n行和第n个匹配行,但不知道如何打印第n个匹配行和所有行,而不是数学

输入示例:

Something else 1
Downloading: file1 1%
Downloading: file1 10%
Something else 2
Downloading: file1 30%
Something else 3
Downloading: file1 40%
Downloading: file2 50%
Downloading: file1 60%
Downloading: file1 100%
Downloading: file2 100%
Something else 4
如果图案为“^Downloading:”,并每第二行打印一次,则输出应如下所示:

Something else 1
Downloading: file1 10%
Something else 2
Something else 3
Downloading: file1 40%
Downloading: file1 60%
Downloading: file2 100%
Something else 4
对于perl粉丝:

perl -nlE 'say unless /Downloading/ && ++$n%2'

显示输入片段和预期输出伟大的东西!标题:“打印与
/Downloading/
匹配的第二行”
perl -nlE 'say unless /Downloading/ && ++$n%2'