将多行合并成一行(awk/sed)

mysql dump的时候,需要忽略视图以免出现definer与本地不一致从而导致失败。
因此写了如下脚本把视图查询出来:

[root@bdd3c0ee821f rds_autorestore]# mysql -e "select concat(table_schema,'.',table_name)as tablename from information_schema.views"|grep -Ev "tablename"
mysql.db_view
mysql.slow_log_view
mysql.user_view
sys.host_summary
sys.host_summary_by_file_io
sys.host_summary_by_file_io_type
sys.host_summary_by_stages
sys.host_summary_by_statement_latency
sys.host_summary_by_statement_type
sys.innodb_buffer_stats_by_schema
sys.innodb_buffer_stats_by_table
sys.innodb_lock_waits
sys.io_by_thread_by_latency
sys.io_global_by_file_by_bytes
sys.io_global_by_file_by_latency

但是要把结果传递给mysqldump 的 ignore-table,所以将结果传递给awk:

mysql -e "select concat(table_schema,'.',table_name)as tablename from information_schema.views"|grep -Ev "tablename"|awk '{printf"--ignore-table=%s ",$0}'

你可能感兴趣的:(Linux/Shell)