I have a directory that contains thousands of txt files. I need to trim the files so every line after line 25 in each file is deleted. I am using Mac OSX 10.14.6.
How can I do this?
Attempts I have made
After researching I think SED in Mac OSX terminal is the best way to do this.
This page gives examples on how to target lines in SED. So I think the SED command I would need is:
sed '1,25!d'
This tells SED to delete everything apart from lines 1 to 25. When I try it on a single file, it works.
I now need to expand it so it works on a directory of files.
This answer says I can do that using SEDs -n and -i flags (it also mentions an -s flag that doesn't work on OSX).
So I think the code should be like this:
sed -n -i '1,25!d' *.txt
But when I try it, I get this error:
sed: 1: "filename": command a expects \ followed by text
I have tried other variations, but none seem to work.