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 ...
- 05-10-2008 #1Just 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.
^^works very well on files with names such as: mysong.mp3 or my-song.mp3Code:ls -1 *.mp3 | sed "s/\(.*\)\.mp3/\1.mp3 \1_128.mp3/" |xargs -n 2 lame -h
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
- 05-11-2008 #2Just 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
- 05-11-2008 #3Linux Guru
- Join Date
- Nov 2007
- Location
- Córdoba (Spain)
- Posts
- 1,513
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:
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.Code:for i in *.[Mm][pP]3; do j=${i// /_}; mv "$i" "$j"; lame -h "$j"; done
- 05-17-2008 #4Just 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 ;]
- 05-18-2008 #5Just Joined!
- Join Date
- May 2008
- Posts
- 34
is it possible to run the command in pwd and have it read and write recurisvely properly?
- 05-18-2008 #6Just 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


Reply With Quote
