1

I want to drop all tables except few of them. I am using the following command:

mysqldump -uroot -pxxx --add-drop-table --no-data database | grep ^DROP | grep -v "^(cache|webform|redirect)([_a-z0-9]?)+$" | mysql -uroot -pxxx database

The regex seems to be fine according this http://www.regexr.com/3aa8k, as the tables that I want to skip are cache*,webform*,redirect. But problem is that it drops everything.

Kara
  • 6,115
  • 16
  • 50
  • 57
George D.
  • 1,630
  • 4
  • 23
  • 41
  • Remove the last `mysql` command together with the pipe in front of it to see what is filtered by `grep`. For some reason, `grep` needs the `|` characters escaped. Also, it's possible that it will interpret `(`, `)` and `+` differently than what you expect. Maybe you can simplify the `regex`. – axiac Jan 28 '15 at 12:43

1 Answers1

0

your regexp is

grep -v "^(cache|webform|redirect)([_a-z0-9]?)+$"

which is extended format (| and + aren't allowed in old grep regexp )

try this instead

grep -Ev "^(cache|webform|redirect)([_a-z0-9]?)+$"

Or it might be possible to escape the meta-characters ?, +, {, |, (, and ) with backslash

Vorsprung
  • 32,923
  • 5
  • 39
  • 63