delete last 3 lines in file in bash ?
- User
delete last 3 lines in file in bash ?
- Assistant
Here are a few ways to drop the last 3 lines of a file in Bash. Pick whichever feels most natural:
- Using
head(most portable)
bashhead -n -3 yourfile.txt > tmp && mv tmp yourfile.txt–
head -n -3prints all but the last 3 lines. – Write that to a temp file and then overwrite the original. - Using
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.