Awk prints every nth matched line and all lines are not math

I know how to print every nth line and nth matched line, but I don't know how to print every nth line matched and all lines are not mathematical.

Input example:

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

      

If the pattern is "^ Load:" and prints out every second line, the output should look like this:

Something else 1
Downloading: file1 10%
Something else 2
Something else 3
Downloading: file1 40%
Downloading: file1 60%
Downloading: file2 100%
Something else 4

      

+3


source to share


2 answers


$ awk '!(/Downloading/ && ++c%2)' file
Something else 1
Downloading: file1 10%
Something else 2
Something else 3
Downloading: file1 40%
Downloading: file1 60%
Downloading: file2 100%
Something else 4

      



+3


source


For perl fans:



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

      

0


source







All Articles