shell - Delete lines from file using sed containing different patterns -


i have dump production db want remove data of tables messages, messages_files, etc because not useful debug/programming on local.

i have been using command remove lines containing kind of data:

sed -i '/create database/d' $current_main_db.sql && sed -i '/use \`okn/d' $current_main_db.sql &&  sed -i '/insert \`messages\`/ d' $current_main_db.sql &&  sed -i '/insert \`messages_email_cron\`/ d' $current_main_db.sql && sed -i '/insert \`messages_users\`/ d' $current_main_db.sql && sed -i '/insert \`messages_files\`/ d' $current_main_db.sql && sed -i '/insert \`messages_mail_list\`/ d' $current_main_db.sql && sed -i '/insert \`messages_sms_cron\`/ d' $current_main_db.sql && sed -i '/insert \`messages_tags\`/ d' $current_main_db.sql && sed -i '/insert \`messages_temp_receivers\`/ d' $current_main_db.sql && sed -i '/insert \`messages_threads\`/ d' $current_main_db.sql; 

it works slow try combine patterns 1 sed command. read manual , find this:

regexp1\|regexp2

matches either regexp1 or regexp2. use parentheses use complex alternative regular expressions. matching process tries each alternative in turn, left right, , first 1 succeeds used. gnu extension.

so tried this:

sed -i '/create database\|use \`okn\|insert \`messages\`\|insert \`messages_email_cron\`\|insert \`messages_users\`\|insert \`messages_files\`\|insert \`messages_mail_list\`\|insert \`messages_sms_cron\`\|insert \`messages_tags\`\|insert \`messages_temp_receivers\`\|insert \`messages_threads\`/ d' $current_main_db.sql; 

but not work, tried use parenthesis every pattern without luck:

sed -i '/(create database\|use \`okn)\|(insert \`messages\`)\|(insert \`messages_email_cron\`)\|(insert \`messages_users\`)\|(insert \`messages_files\`)\|(insert \`messages_mail_list\`)\|(insert \`messages_sms_cron\`)\|(insert \`messages_tags\`)\|(insert \`messages_temp_receivers\`)\|(insert \`messages_threads\`)/d' 

am doing wrong?

i search in , find similar questions not work me.

grep should suffice:

grep -ve '^(insert `messages(_email_cron|_users|_files|_mail_list|_sms_cron|_tags|_temp_receivers|_threads)`|create database|use `okn)' file 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -