bash - 如何解析rsync统计数据?

标签 bash rsync automator

由于 rsync 使用 -stats 选项运行,我在日志末尾得到如下所示的内容:

Number of files: 619
Number of files transferred: 0
Total file size: 134.50M bytes
Total transferred file size: 0 bytes
Literal data: 0 bytes
Matched data: 0 bytes
File list size: 22880
File list generation time: 0.250 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 22.90K
Total bytes received: 20

我想在自动机的通知中显示传输的文件数传输的文件总大小。所以我应该以某种方式提取这些数据并进一步传递。我怎样才能做到呢? grep 在这里有帮助吗?

最佳答案

使用 awk 你可以这样做:

awk '/Number of files|Number of files/{print $NF}' file
619
0

如果您想要完整的行,那么:

awk '/Number of files|Number of files/' file
Number of files: 619
Number of files transferred: 0

关于bash - 如何解析rsync统计数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21060705/

相关文章:

bash - 如何在 Bash 脚本中解码希捷的硬盘日期代码

rsync - 视觉 SVN 服务器 : Guide on Pre/Post Commit Hooks

linux - rsync 守护进程行为异常

macos - 如何使用 Automator 调整 Visual Studio Code 窗口的大小?

string - "set foo to text returned of"代表数字吗?

javascript - 将纯文本转换为 json

bash - Shell 脚本 - CURL 脚本返回错误

windows - Cygwin 命令可从命令行运行,但不能从脚本运行

macos - 单击 Finder 中的任意位置时,AppleScript 会在**当前**文件夹中打开终端?

BASH 脚本期待,当我需要其他的时候