How to Remove Every n-th Line From a File

Exacto

A bit of googling directed me to this article, which was about sampling a file. What I really wanted was to remove every fifth line from a file.

Here is the input file:

1
00:00:06,244 --> 00:00:09,004
The public has a very romantic idea of what wine's about.
Le public a une idée très romantique du vin.

2
00:00:09,984 --> 00:00:14,373
They think it's some little guy, like me, working in the cellar,
On pense que c'est un petit producteur, comme moi, qui travaille à la cave,

3
00:00:14,473 --> 00:00:16,741
working in the vineyard, bringing the grapes in.
qui travaille dans le vignoble, qui vendange ses raisins.

And I wanted to have that output:

1
00:00:06,244 --> 00:00:09,004
Le public a une idée très romantique du vin.

2
00:00:09,984 --> 00:00:14,373
On pense que c'est un petit producteur, comme moi, qui travaille à la cave,

3
00:00:14,473 --> 00:00:16,741
qui travaille dans le vignoble, qui vendange ses raisins.

 

So this made the trick:

awk '{if ((count++ +2)%5!=0) print $0;}' input_file.srt > output_file.srt
Advertisements

Got a comment?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: