How do I limit (or truncate) text file by number of lines?
I would like to use a terminal/shell to truncate or otherwise limit a text file to a certain number of lines. I have a whole directory of text files, for each of which only the first ~50k lines are useful. How do I delete all lines over 50000? In-place truncation To truncate the file in-place with sed, you can do the following: sed -i '50001,$ d' filename -i means in place. d means delete. 50001,$ means the lines from 50001 to the end. You can make a backup of the file by adding an extension argument to -i , for example, .backup or .bak : sed -i.backup '50001,$ d' filename In OS-X or FreeBSD