linuxbashdebiandebian-basedcalibre

Get all the numbers on the start of the line in output from grep


hello I am writing a news downloader from command line for calibre (calibre-ebooks.com) the script gets the id of an ebook from calibre DB using this command

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

but it works only for id 1-9

tried searching on the web and experimenting myself but I can't find anything

if you wonder how the output from calibredb looks like:

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

(i need that first unique id)


Solution

  • I suspect you would be better off with awk if you want to find lines that start with digits and contain "Benchmark":

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

    Or, if you like grep:

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