Glam Prestige Journal

Bright entertainment trends with youth appeal.

I need to remove the first 42 lines of a 2GB SQL dump.

I know I can view the first lines using:

head -n 44 dump.sql

But is there anyway to edit or remove them?

8 Answers

If you want to just view the lines from the 43rd on you can use

tail -n +43 dump.sql

The + sign is important - without it, tail will print the last 43 lines instead. Alternatively with 'sed'

sed 1,42d dump.sql

If you want to really delete the first 42 lines from the original file then you can make sed make the change inplace with the -i option

sed -i 1,42d dump.sql
5

This seems to be the easiest:

sed '1,42d' test.sql > test2.sql

Remove lines 1-42 from test.sql and save as test2.sql

1

try this,

tail -n +43 dump.sql > dump_new.sql

You can use Vim in Ex mode:

ex -s -c '1d42|x' dump.sql
  1. 1 move to first line

  2. 42 select 42 lines

  3. d delete

  4. x save and close

3

Because of sed discrepancies across Linux and Mac, I resolved to use tail -n +43 dump.sql > new.sql format.

2

Just to add this. If you're on a mac you need to add the backup extension. Answer from this post.

sed -i '.bak' 1,42d dump.sql

Sorry, I can't give you actual code right now. However, try looking at something along the lines of

tail -n arcv(`wc -l`) -44

What this should do (once properly formatted) is count the number of lines in the file (wc -l), subtract 44 from it (-44) and then print out everything starting with the 45th line in the file.

Hope this helps and good luck.

1

Try this,

head -n 42 dump.sql > tmp; cat dump.sql | grep -vxf tmp > dump.sql.new; rm tmp

or,

a=$(cat dump.sql| wc -l); tail -n "$((a-42))" dump.sql > dump.sql.new

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy