【问题标题】:Get all the numbers on the start of the line in output from grep从 grep 的输出中获取行首的所有数字
【发布时间】:2017-03-25 08:42:21
【问题描述】:

你好,我正在从命令行为 calibre (calibre-ebooks.com) 编写新闻下载器,脚本使用此命令从 calibre DB 获取电子书的 id

 calibredb list --with-library '/mediacenter/media/Książki' | grep --line buffered "Benchmark.pl" | cut -c 1

但它仅适用于 id 1-9

尝试在网络上搜索并尝试自己,但我找不到任何东西

如果您想知道 calibredb 的输出是什么样子的:

uniqueid name         date                 author
10       Benchmark.pl [pią, 24 mar 2017]   calibre

(我需要第一个唯一 ID)

【问题讨论】:

    标签: linux bash debian debian-based calibre


    【解决方案1】:

    如果您想查找以数字开头并包含“基准”的行,我怀疑您最好使用awk

    calibredb ... | awk '/^[0-9]+/ && /Benchmark/ {print $1}'
    

    或者,如果你喜欢grep

    calibredb ... | grep "Benchmark" | grep -Eo "^[0-9]+"
    

    【讨论】:

      猜你喜欢
      • 2021-07-23
      • 2014-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-25
      • 2020-01-21
      • 1970-01-01
      相关资源
      最近更新 更多