开发者

xargs: unterminated quote

I'm trying to convert so开发者_运维问答me .flac files to .mp3, that can I import into iTunes. I tried with find, xargs and ffmpeg, but xargs give me a unterminated quote error (because I have quotes in filename).

That`s my command line:

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

It`s stop and raise an error in filename "Talkin' Loud Ain't Saying Nothin'.flac".

Some tricks to make this one work?

-- Solved with find only -- find . -type f -name "*.flac" -exec ffmpeg -i {} -ab 192k -acodec libmp3lame -ac 2 {}.mp3 \;


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

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

You may also want to use {.}.mp3 to get rid of the .flac:

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

Watch the intro video to learn more: http://www.youtube.com/watch?v=OpaiGYxkSuQ


Some versions of xargs support a custom delimiter. If that's the case, it's as easy as adding -d'\n' to indicate that the newline character should be used to separate items (which generally makes sense).

In that case, you'd use it as follows:

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


From the egrep manpage:

-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.

So use -Z with egrep, and -0 with xargs

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜