加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

bash – 从mysqldump输出中删除特定表的插入数据(sed?)

发布时间:2020-12-15 22:27:36 所属栏目:安全 来源:网络整理
导读:我有一个巨大的 mysqldump输出,并希望排除特定表的插入. 该文件如下所示: ---- Dumping data for table `big_table`--INSERT INTO `big_table` ...INSERT INTO `big_table` ...---- Table structure for table `next_table`-- 如何删除介于“为表big_table
我有一个巨大的 mysqldump输出,并希望排除特定表的插入.

该文件如下所示:

--
-- Dumping data for table `big_table`
--

INSERT INTO `big_table` ...
INSERT INTO `big_table` ...


--
-- Table structure for table `next_table`
--

如何删除介于“为表big_table转储数据”和下一个“表结构表”之间的插入文件太大而无法放入文本编辑器中.

解决方法

使用sed的一种解决方案.它搜索文字之间的所有行 – 转储表’big_table’的数据和 – 表的表结构.并评论那些不以 – 开头的行.

假设infile的内容:

1
2
3
4
--
-- Dumping data for table `big_table`
--

INSERT INTO `big_table` ...
INSERT INTO `big_table` ...


--
-- Table structure for table `next_table`
--
1
2
3
4
5
6

运行命令:

sed -e '
    /-- Dumping data for table `big_table`/,/-- Table structure for table/ { 
        /^--/! s/^/--/ 
    }
' infile

输出如下:

1
2
3
4
--
-- Dumping data for table `big_table`
--
--
--INSERT INTO `big_table` ...
--INSERT INTO `big_table` ...
--
--
--
-- Table structure for table `next_table`
--
1
2
3
4
5
6

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读