parallel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to parallelize find|while read do; ffprobe, grep and get the fil


From: D
Subject: Re: How to parallelize find|while read do; ffprobe, grep and get the filenames?
Date: Sat, 12 Nov 2022 21:58:29 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2

Hi,
I figured it out myself (from some stackoverflow "FILE_BASENAME"-post)
(but was gaming and didn't come to the `column` part yet), but thanks
for `parallel` and reply :)

func() {
    FILENAME=$1
#    FILE_BASENAME=`echo ${FILENAME##*/}`
#    echo $FILE_BASENAME
    URL=$(ffprobe -hide_banner "$FILENAME" 2>&1| grep -i 'http\|www')
    if [ "$URL" != "" ]; then
        echo -e "$FILENAME\t$URL"
    fi
}
export -f func
#time parallel func :::: ~/filelist|wc -l
time find . -type f -iname "*.flac" -print0|parallel -0 func

Initially I didn't like to see a function and additional export line,
but I'm fine with it now as it tidies things up and helps understanding.

On 12.11.22 um 16:53 Ole Tange wrote:
On Sat, Nov 12, 2022 at 2:55 PM D <dcmhoybdpzkh@web.de> wrote:
Hello,

I'm trying to parallelize my Bash shell script:

find . -type f -iname "*.flac" -print0 | while read -d $'\0' FILENAME; do
      INFOS=$(ffprobe -hide_banner "$FILENAME" 2>&1)
      URL=$("$INFOS"|& grep -i 'http\|www')
      if [ "$URL" != "" ]; then
          echo -e "$FILENAME\t$URL"
      fi
done | column -t -s $'\t'
doit() {
    FILENAME="$1"
    INFOS=$(ffprobe -hide_banner "$FILENAME" 2>&1)
    URL=$("$INFOS"|& grep -i 'http\|www')
    if [ "$URL" != "" ]; then
        echo -e "$FILENAME\t$URL"
    fi
}
export -f doit
find . -type f -iname "*.flac" -print0 | parallel doit |
    column -t -s $'\t'

I think you have misunderstood how GNU Parallel works.

You should spend 20 minutes reading chapter 1+2:
https://doi.org/10.5281/zenodo.1146014 (Print:
https://www.lulu.com/shop/ole-tange/gnu-parallel-2018/paperback/product-23558902.html)

/Ole




reply via email to

[Prev in Thread] Current Thread [Next in Thread]