LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 08-22-2005, 10:21 AM   #1
chun-mee
LQ Newbie
 
Registered: Jan 2005
Distribution: Slackware
Posts: 8

Rep: Reputation: 0
How to perform an action (a command) on multiple files with the FOR loop?


I need to automate the actions that I perform on a batch of files.
I perform a
Code:
command inputfile.oldext outputfile.newext
type of action.

The files are
Code:
track_01.wav
track_02.wav
...
track_n.wav
(But they could be any filetype and I could need to perform any similar command upon them.)

When I issue

Code:
bladeenc track_01.wav track_01.mp3
I get an mp3 file in addition to the original wav.
How do I build a FOR loop that will

Code:
command (trackname).wav (trackname).mp3
for each file and then stop at the last file?

I have been told that the FOR loop plus setting a smart variable for the filename could do that, but the books I have checked describe an older command, FOREACH, no longer available in my distro.
Thank you guys!
 
Old 08-22-2005, 10:26 AM   #2
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Puppy
Posts: 3,048

Rep: Reputation: 95
Code:
 for file in *.lsp;do
 echo file is:$file
done

file is:client.lsp
file is:globals.lsp
file is:grid.lsp
file is:hash.lsp
file is:noughts.lsp
file is: play.lsp
file is:server.lsp
 
Old 08-22-2005, 01:14 PM   #3
chun-mee
LQ Newbie
 
Registered: Jan 2005
Distribution: Slackware
Posts: 8

Original Poster
Rep: Reputation: 0
Am not experienced reading these without an example;
Do you mean
for file in *.lsp; do
bladeenc
echo file is:$file
done

?

and what do these mean?
file is:client.lsp
file is:globals.lsp
file is:grid.lsp
Sorry but if I knew then I would not be posting here. I am not a programmer.
I was hoping for an example I could paste here and then learn from it if it works. Many thanks.
 
Old 08-22-2005, 10:44 PM   #4
crabboy
Moderator
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,755

Rep: Reputation: 88
Billy wrote the loop that you would need. He used .lst file extension instead of .wav since that is likely what he had to test with on his machine, and he used echo, to show the file names, instead of executing your command.

Here would be the script as you would use it:
Code:
#!/bin/sh

for FILE in `ls *.wav`; do

  NEWFILE=`echo $FILE | sed 's/\.wav/\.mp3/' `
  bladeenc $FILE $NEWFILE

done
Careful with the single quotes, the direction does matter!
 
Old 08-23-2005, 03:11 AM   #5
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Puppy
Posts: 3,048

Rep: Reputation: 95
sorry for lack of explanation...
was a bit busy at work,


thanks a lot crabboy
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't perform root command by using Sudo acbenny Linux - General 6 05-07-2008 08:19 PM
redhat 9.0 how to use the command 'find' with the action -exec arvin_shu Linux - Newbie 3 11-30-2005 07:09 AM
Cannot mount more than 8 iso image files as loop device marsim Debian 4 11-09-2004 04:05 AM
Help I need help tarring multiple files in multiple directories VisionZ Linux - Newbie 28 03-25-2004 05:25 PM
i am getting command not found error when i am trying to perform commands in linux? sunilmuddu Linux - Newbie 7 03-24-2004 12:18 AM


All times are GMT -5. The time now is 03:30 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration