removing the top N lines from a file
Just a quick post here.
I was messing around with some pretty large text files yesterday. I had a file with 2.9 million insert statements (one per line) that I was running on a database. It was taking forever so I stopped it. I new how many of the insert statements had run so I needed to get rid of the top million and a half so that they were not inserted again. I came across this nifty one-liner that made it really easy and didn’t take too long:
sed '1,1500000d' inserts.sql > inserts2.sql
Now I will explain what I understand it to be doing. sed is a command that is very powerful (I don’t know the first thing about using it really) for working with text and files. The 1,1500000 indicates that I want to do something to lines 1-1500000 of the file. The d tells sed that I want to delete those lines. Then specify the file you want to do that do and output the remaining contents (>) to a new file insert2.sql.
Pretty simple, but sed can be pretty involved.
