Linux - Delete all but not last n lines, Leave last few lines and delete all
Delete all but not last n lines
How do I delete a huge file except last n lines of a file?vi editor has a feature called "ex", By using it you can delete all lines of a file except n lines from a file
Create a file with n lines
# for i in $(seq 1 2500); do echo "$i" >>delete_test ; done
For example the above will create a file called delete_test from 1 to 2500 lines
Delete all lines but not last 500 lines
# ex -c '1,$-500d' -c 'wq' delete_testThis will delete all the lines excet last 500 lines from the file
The topic on Linux - Delete all but not last n lines is posted by - Maha
Hope you have enjoyed, Linux - Delete all but not last n linesThanks for your time