Welcome to Linux Forums!

With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.

Linux Forum ArticlesLinux ForumsLinux Forum DownloadsLinux Hosts
Home|Register|FAQ|Member List|Calendar|Unanswered Posts|Forum Rules|Today's Posts|Advanced Search|
SEARCH FOR IN
Go Back   Linux Forums > GNU Linux Zone > Linux Programming & Scripting
Reload this Page Question about batch file processing
Linux Forums
Linux Forums
Welcome To The Linux Forums!
Welcome to Linux Forums. We pride ourselves in being one of the largest Linux communities on the web, we encourage you to REGISTER on our forums and participate in the community. There are over 150,000 members ready to answer your questions. JOINING US today will allow you to make new posts, get support, send messages to other members and submit downloads to our downloads directory and many other great features!

Linux Programming & Scripting C, Perl, PHP, Bash Scripts, anything programming or script related post in here!

Reply
 
Thread Tools Display Modes
Old 05-10-2008   #1 (permalink)
5pyd3r
Just Joined!
 
Join Date: May 2008
Posts: 7
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
5pyd3r is offline   Reply With Quote
Old 05-11-2008   #2 (permalink)
eggi
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
__________________
Tips, Tricks and Advice For Unix/Linux Users and Administrators of all skill levels - http://linuxshellaccount.blogspot.com
---
Help With UNIX Commands Here, As Well - www.mysysad.com
eggi is offline   Reply With Quote
Old 05-11-2008   #3 (permalink)
i92guboj
Linux Engineer
 
Join Date: Nov 2007
Location: Córdoba (Spain)
Posts: 884
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.
i92guboj is online now   Reply With Quote
Old 05-17-2008   #4 (permalink)
5pyd3r
Just Joined!
 
Join Date: May 2008
Posts: 7
thx bro that went easy and smooth and it took care of the space issue in the filenames ;]
5pyd3r is offline   Reply With Quote
Old 05-18-2008   #5 (permalink)
5pyd3r
Just Joined!
 
Join Date: May 2008
Posts: 7
is it possible to run the command in pwd and have it read and write recurisvely properly?
5pyd3r is offline   Reply With Quote
Old 05-18-2008   #6 (permalink)
eggi
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)

Quote:
for i in `find . -name "*.[Mm][pP]3"`; do j=${i// /_}; mv "$i" "$j"; lame -h "$j"; done
__________________
Tips, Tricks and Advice For Unix/Linux Users and Administrators of all skill levels - http://linuxshellaccount.blogspot.com
---
Help With UNIX Commands Here, As Well - www.mysysad.com
eggi is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


All times are GMT. The time now is 04:34 AM.

Powered by vBulletin 3.6.8 ©2000 - 2007, content relevant URLs by vBSEO, Property of Core Root.

Content Relevant URLs by vBSEO 3.0.0