将传递给 xargs 的数据放在一行中两次

编程入门 行业动态 更新时间:2024-10-09 19:23:38
本文介绍了将传递给 xargs 的数据放在一行中两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

tmp 文件包含:

database_1 database_2 database_3

我想为上述文件中的每一行运行一个类似mysqldump DATABASE > database.sql && gzip database.sql"的命令.

I want to run a command like "mysqldump DATABASE > database.sql && gzip database.sql" for each line in the above file.

我已经知道了 cat/tmp/database-list |xargs -L 1 mysqldump -u root -p

I've got as far as cat /tmp/database-list | xargs -L 1 mysqldump -u root -p

我想我想知道如何将传递给 xargs 的数据多次放入(而不只是放在最后)

I guess I want to know how to put the data passed to xargs in more than once (and not just on the end)

以下命令会将每个数据库转储到其自己的 .sql 文件中,然后对其进行 gzip.

the following command will dump each database into its own .sql file, then gzip them.

mysql -u root -pPASSWORD -B -e 'show databases' | sed -e '$!N; s/Database\n//' | xargs -L1 -I db mysqldump -u root -pPASSWORD -r db.backup.sql db; gzip *.sql

推荐答案

在您自己的示例中,您使用 &&在一行上使用两个命令 - 那么为什么不这样做

In your own example you use && to use two commands on one line - so why not do

cat file | xargs -L1 -I db mysqldump db > db.sql && cat file | xargs -L1 -I db gzip database.sql

如果您真的想仅使用 xargs 在一行中完成所有操作.虽然我相信

if you really want to do it all in one line using xargs only. Though I believe that

cat file | xargs -L1 -I db mysqldump db > db.sql && cat file; gzip *.sql

会更有意义.

更多推荐

将传递给 xargs 的数据放在一行中两次

本文发布于:2023-07-09 10:37:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1085659.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:放在   两次   数据   xargs

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!