Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formatting SHOW ENGINE INNODB STATUS outputs when “\n” are embedded as Text

I am referring to this link

I have an output via this command:

mysql -e "show engine innodb status" -u -p database > mydumpfile.txt

However, any editor I use (less, vim, kwrite) is showing the \n instead of a real new line.

How can I accomplish the replacement with sed, awk or any other tool in a shell?

like image 485
Torsten Avatar asked Sep 03 '25 10:09

Torsten


2 Answers

You can use the following syntax of sed.

sed -i -e 's|\\n|\n|g' mydumpfile.txt

If you want the direct output properly from mysql then use --table option in mysql command.

mysql --table -e "show engine innodb status" -u -p database > mydumpfile.txt
like image 176
Sriharsha Kalluru Avatar answered Sep 05 '25 01:09

Sriharsha Kalluru


Try simply adding \G to the SQL command, for example:

mysql -e "show engine innodb status\G" -u -p database > mydumpfile.txt

Or try running the mysql client with the -r (or --raw) switch.

mysql -re "show engine innodb status" -u -p database > mydumpfile.txt

With either of these methods, you can also skip the intermediate file and just pipe into less. Such as:

mysql -re "show engine innodb status" -u -p database | less

Side note, specifying the database is not necessary. I included it only for parity to your question. If you also have setup a my.cnf file, and therefore don't need to enter a password, you can shorten this to:

mysql -re "show engine innodb status" | less

like image 28
Joshua Huber Avatar answered Sep 05 '25 01:09

Joshua Huber