-- Current Database: `db1` -- Current Database: `db2` -- Current Database: `db3` -- Current Database: `db4` -- Current Database: `db5` -- Current Database: `db6` ....Thanks to this thread on StackOverflow, the solution is simple, just run below command to extract all lines between “Current Database: `db4`” and “Current Database: `db5`“:
sed '/Current Database: `db4`/,/Current Database: `db5`/!d' dump.sql > db4.sqlWhat above command does is to search for lines “Current Database: `db4`” and “Current Database: `db5`“, and delete everything that is NOT between those two lines (!d means not matching then delete, “,” means between the lines). Method 2 Firstly grep the pattern and print out the line numbers:
ubuntu@localhost:~/chenhui$ grep -n 'Current Database' dump.sql 19: -- Current Database: `db1` 382: -- Current Database: `db2` 744: -- Current Database: `db3` 1137: -- Current Database: `db4` 3401: -- Current Database: `db5` 5604: -- Current Database: `db6` ....Then, use those line number to capture all lines in between:
sed -n 1137,3401p dump.sql > db4.sqlMore information can be found from this blog post. Hope above helps!!