Find the answer to your Linux question:
Results 1 to 6 of 6
Because, the original thread was closed this post is a continuation from the url: http://www.linuxforums.org/forum/lin...rocessing.html I guess a mod can merge it later. Code: ls -1 *.mp3 | sed "s/\(.*\)\.mp3/
.mp3 ...
  1. #1
    Just Joined!
    Join Date
    May 2008
    Posts
    34

    Question about batch file processing

    Because, the original thread was closed this post is a continuation from the url:
    http://www.linuxforums.org/forum/lin...rocessing.html
    I guess a mod can merge it later.
    Code:
    ls -1 *.mp3 | sed "s/\(.*\)\.mp3/\1.mp3 \1_128.mp3/" |xargs -n 2 lame -h
    ^^works very well on files with names such as: mysong.mp3 or my-song.mp3
    my problem is the spaces in between instead of a symbol for e.g. 1 - my fav song.mp3
    Can someone please tell me whatelse needs to be added to to the command so that it reads the files with spaces and writes them back in the same format.
    example:1 - my fav song_128.mp3

  2. #2
    Just Joined!
    Join Date
    Apr 2008
    Posts
    35
    Hey There,

    Depending on your xargs, you can use either the -i or -I flag. For instance

    xargs -n 2 lame -h

    becomes

    xargs -I var -n 2 lame -h "var"

    so you can quote those filenames with spaces

    Cheers,

    Mike

  3. #3
    Linux Guru
    Join Date
    Nov 2007
    Location
    Córdoba (Spain)
    Posts
    1,513
    Quote Originally Posted by 5pyd3r View Post
    Because, the original thread was closed this post is a continuation from the url:
    http://www.linuxforums.org/forum/lin...rocessing.html
    I guess a mod can merge it later.
    Code:
    ls -1 *.mp3 | sed "s/\(.*\)\.mp3/\1.mp3 \1_128.mp3/" |xargs -n 2 lame -h
    ^^works very well on files with names such as: mysong.mp3 or my-song.mp3
    my problem is the spaces in between instead of a symbol for e.g. 1 - my fav song.mp3
    Can someone please tell me whatelse needs to be added to to the command so that it reads the files with spaces and writes them back in the same format.
    example:1 - my fav song_128.mp3
    That command is utterly complex and cryptic for my tastest. I don't like to use the output of ls for these things, it can only create problems. Besides that, there's no need to use xargs (and it can potentially create problems if the file list is long enough).

    In bash I would do:

    Code:
    for i in *.[Mm][pP]3; do j=${i// /_}; mv "$i" "$j"; lame -h "$j"; done
    If you use any other shell you still need to use sed. But this will work regardless of the number of files, and don't needs ls or xargs for anything.

  4. #4
    Just Joined!
    Join Date
    May 2008
    Posts
    34
    thx bro that went easy and smooth and it took care of the space issue in the filenames ;]

  5. #5
    Just Joined!
    Join Date
    May 2008
    Posts
    34
    is it possible to run the command in pwd and have it read and write recurisvely properly?

  6. #6
    Just Joined!
    Join Date
    Apr 2008
    Posts
    35
    Hey There,

    I think you can just do this (easiest to type, maybe not the most efficient way)

    for i in `find . -name "*.[Mm][pP]3"`; do j=${i// /_}; mv "$i" "$j"; lame -h "$j"; done

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...