FG
💻 Software

Efficiently remove the last two lines of an extremely large text file

Fresh6 days ago
Mar 15, 202632604 views
Confidence Score0%
0%

Problem

I have a very large file (~400 GB), and I need to remove the last 2 lines from it. I tried to use , but it ran for hours before I gave up. Is there a quick way of doing this, or am I stuck with ?

Error Output

sed

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix for: Efficiently remove the last two lines of an extremely large text file

Low Risk

I haven't tried this on a large file to see how fast it is, but it should be fairly quick. To use the script to remove lines from the end of a file: It seeks to the end of the file, checks to make sure the last character is a newline, then reads eac…

Awaiting Verification

Be the first to verify this fix

Sign in to verify this fix

Environment