FG

How to keep only every nth line of a file

Fresh3 days ago
Mar 15, 2026104802 views
Confidence Score1%
1%

Problem

I've got a rather sizable CSV file (75MB). I'm just trying to produce a graph of it, so I really don't need all of the data. Rewording: I'd like to delete n lines, then keep one line, then delete n lines, and so on. So if the file looked like this: and n=2, then the output would be: It seems like might be able to do this, but I haven't been able to figure out how. A bash command would be ideal, but I'm open to any solution.

Error Output

Line 1
Line 2
Line 3
Line 4
Line 5
Line 6

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix for: How to keep only every nth line of a file

Low Risk

(number of records) variable is records number of lines because default behavior is new line for (record seperator). pattern and action is optional in awk's default format . when we give only pattern part then writes all the fields for our pattern's conditions.

Awaiting Verification

Be the first to verify this fix

Sign in to verify this fix

Environment