Xargs: unterminated quote

I am trying to convert some .flac files to .mp3 that can be imported into iTunes. I tried to find find, xargs and ffmpeg, but xargs give me an inexhaustible quote error (because I have quotes in the file name).

This is my command line:

MacKassner:Geto Boys kassner$ find . -type f | egrep "\.flac$" | xargs -I {} ffmpeg -i {} -ab 192k -acodec libmp3lame -ac 2 {}.mp3

It will stop and raise an error in the file name. "Talkin" Loud Is Not Saying Nothin'.flac ".

Some tricks to make this work?

- It is solved only with the search - to find. -type f -name "* .flac" -exec ffmpeg -i {} -ab 192k -acodec libmp3lame -ac 2 {} .mp3 \;

+3
source share
3 answers

Use GNU Parallel. It is specially built for this purpose:

MacKassner:Geto Boys kassner$ find . -type f | egrep "\.flac$" | parallel ffmpeg -i {} -ab 192k -acodec libmp3lame -ac 2 {}.mp3

You can also use {.}. mp3 to get rid of .flac:

MacKassner:Geto Boys kassner$ find . -type f | egrep "\.flac$" | parallel ffmpeg -i {} -ab 192k -acodec libmp3lame -ac 2 {.}.mp3

, : http://www.youtube.com/watch?v=OpaiGYxkSuQ

+4

egrep:

-Z, --null
          Output  a  zero  byte  (the  ASCII NUL character) instead of the character that normally follows a file
          name.  For example, grep -lZ outputs a zero byte after each file name instead  of  the  usual  newline.
          This  option  makes  the  output  unambiguous,  even  in  the presence of file names containing unusual
          characters like newlines.  This option can be used with commands like find -print0, perl -0,  sort  -z,
          and xargs -0 to process arbitrary file names, even those that contain newline characters.

-Z egrep -0 xargs

+1

Some versions of xargs support custom separator. If so, then simply add -d'\n'to indicate that the newline should be used to separate items (which usually makes sense).

In this case, you will use it as follows:

# find files_containing_quotes/ | xargs -d'\n' -i{} echo "got item '{}'"
+1
source

Source: https://habr.com/ru/post/1792951/


All Articles