how to remove 3 lines in row if the first line contain a specific character? <p>I have a data file (which a matrix with 290 lines and 2 columns) like this:</p> <pre><code># RIR1 ABABABABABABABABAA ABABABABABABABABBA # WR ABABABABABABABABAB BABABBABABABABABAA # BR2 ABABABABABABABBABA ABBABABABABABABABA # SL AAABABABABABABBABA AAABBABABABABABABA </code></pre> <p>I would like to remove all the data that are for SL and WR (as example). So I will have only:</p> <pre><code># RIR1 ABABABABABABABABAA ABABABABABABABABBA # BR2 ABABABABABABABBABA ABBABABABABABABABA </code></pre> <p>I know how to remove one line that start or contain something but no idea how to do with 3 lines in row.</p> <p>this is what I use for one line:</p> <pre><code>old&lt;-old[!substr(old[1,],1,5)=="# BR2",] old&lt;-old[!substr(old[1,],1,6)=="# RIR1",] </code></pre> <p>thanks in advance.</p>