How to delete the first line of a megaheavy SQL file?

Asked

Viewed 81 times

2

I have a "mega heavy" SQL file that doesn’t open in the sublime, nor in the notepad nor in gedit. I just need to delete the first line Use nome_database; to be able to import via the mysql Workbench or command line on the terminal:
mysql -hmeu_servidor -uroot -psenha banconovo < path/meuarquivo.sql.

The problem is that the name of the bank is different, so it is making a mistake, it does not find the base. Does anyone have an alternative to delete this line without opening the file?

Can be via script edit.sh or via PHP edit.php. Or any better suggestions...

  • "Mega heavy" gives how much in bytes?

  • he weighs 1.5GB... ta fuck. I got so from the customer.

  • You can use a hexadecimal editor instead. Hxd is very good.

  • How do I do that?

  • https://mh-nexus.de/en/hxd/ - make a backup before you try. It is suggested not to change the size of the strings. For example, if the name is shorter, complete with spaces outside the quotes. If it is longer, you need to do a little contortion...

  • I use linux... has a version for Ubuntu?

  • This type of editor usually has to mount, I just won’t know the name of some for linux. If you have practice with the terminal, can do using text mode, even have more tools for it.

  • I haven’t tested with "vi" yet.

  • For the record, if you ever need vim, has the :%!xxd to enter hexa mode (currently vi is shortcut pro vim on almost all systems) - but I commented of curiosity, pq open with the vim do not need to use hexa mode in this specific case, of course.

  • try this on the terminal: sed '1d' original.sql > modificado.sql (manual http://linux.die.net/man/1sed)

  • worked here, with the "vi", thank you!

Show 6 more comments

2 answers

0

There are several ways to do this on Linux:

1) Using tail (removing first line):

$ tail -n +2 arquivo.sql > /tmp/arqtmp.sql; mv /tmp/arqtmp.sql arquivo.sql

2) Using sed (removing first line):

$ sed -i '1d' arquivo.sql 

3) Using grep (detecting the line with the content and removing):

$ grep -v 'Use nome_database;' arquivo.sql > /tmp/arqtmp.sql; mv /tmp/arqtmp.sql arquivo.sql

I hope I’ve helped!

0


For the record, the way I did it was by getting into the terminal, and typing:

vi arquivo_megapesado.sql

Inside the editor vi, typed: i, in order to edit the file, I deleted the piece I wanted, then I pressed the key esc to exit edit mode and typed :wq! to save and quit the editor.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.