LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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
  Search this Thread
Old 02-10-2010, 06:39 PM   #1
danpaluska
LQ Newbie
 
Registered: Dec 2009
Location: new york city and sometimes boston and hopefully sometime somewhere warmer
Distribution: i'm trying to remain agnostic. but fedora and ubuntu so far.
Posts: 20

Rep: Reputation: 0
for f in *.mp4,*.mov,*.ogv ?? how can you use multiple filetypes? shell script


in code such as
Code:
for f in *.mp4;do

# perform operations on f here
echo $f

done
is it possible to specify multiple filetypes?
i have used *.m* for multiple movie types on my mac, .mov,m4v,mp4 but it doesn't cover ogv.
i'd like to get ogv and mp4 both on my linux box. is there syntax for this?

thanks,
dan
 
Old 02-10-2010, 06:45 PM   #2
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
Code:
for f in ./*.mp3 ./*.ogg ./*.mkv ; do
   echo "$f"
done

Last edited by tuxdev; 02-10-2010 at 09:46 PM.
 
Old 02-10-2010, 06:50 PM   #3
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Quote:
Originally Posted by danpaluska View Post
in code such as
Code:
for f in *.mp4;do

# perform operations on f here
echo $f

done
is it possible to specify multiple filetypes?
i have used *.m* for multiple movie types on my mac, .mov,m4v,mp4 but it doesn't cover ogv.
i'd like to get ogv and mp4 both on my linux box. is there syntax for this?

thanks,
dan
How about
Code:
for f in *.m* *.ogv; do
    echo "$f"
done
 
Old 02-10-2010, 07:06 PM   #4
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
tuxdev was faster.
However you might want to add an if in your loop:

Code:
for s in ./*.m* ./*.ogv; do
 if [[ '*' != "${s:2:1}" ]]; then
  echo "$s"
 fi
done
Without 'if' you will get output like
Code:
*.ogv
if there are no files with 'ogv' suffix. The if-condition prevents that.

Last edited by crts; 02-10-2010 at 07:12 PM. Reason: readability; pitfall
 
Old 02-10-2010, 07:06 PM   #5
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
Quote:
Originally Posted by tuxdev View Post
Code:
for f in ./*.mp3 ./*.ogg ./*.mkv ; then
   echo "$f"
done
It should be 'do' and not 'then'.
 
Old 02-10-2010, 07:45 PM   #6
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by crts View Post
tuxdev was faster.
However you might want to add an if in your loop:

Code:
for s in ./*.m* ./*.ogv; do
 if [[ '*' != "${s:2:1}" ]]; then
  echo "$s"
 fi
done
Without 'if' you will get output like
Code:
*.ogv
if there are no files with 'ogv' suffix. The if-condition prevents that.
no need. set nullglob before commencing the for loop
Code:
shopt -s nullglob
 
Old 02-12-2010, 12:10 PM   #7
danpaluska
LQ Newbie
 
Registered: Dec 2009
Location: new york city and sometimes boston and hopefully sometime somewhere warmer
Distribution: i'm trying to remain agnostic. but fedora and ubuntu so far.
Posts: 20

Original Poster
Rep: Reputation: 0
thanks all!

i had that *.ogv problem as well so good to know that solution.
 
Old 02-14-2010, 08:06 AM   #8
vonbiber
Member
 
Registered: Apr 2009
Distribution: slackware 14.1 64-bit, slackware 14.2 64-bit, SystemRescueCD
Posts: 533

Rep: Reputation: 129Reputation: 129
Quote:
Originally Posted by danpaluska View Post
in code such as
Code:
for f in *.mp4;do

# perform operations on f here
echo $f

done
is it possible to specify multiple filetypes?
i have used *.m* for multiple movie types on my mac, .mov,m4v,mp4 but it doesn't cover ogv.
i'd like to get ogv and mp4 both on my linux box. is there syntax for this?

thanks,
dan
you can also do this
Code:
for f in *.{mov,m4v,mp4}
do
  #process $f
  echo $f
done
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash wmv to ogv script True`Colors Programming 5 11-20-2010 11:11 AM
Runs Multiple shell script inside a main script using crontab srimal Linux - Newbie 4 10-22-2009 06:19 PM
how do I search for multiple filetypes? fisayo Linux - General 4 07-19-2005 07:05 AM
shell command to grab filetypes recursively Nice-n-Slow Programming 1 05-13-2005 07:05 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:17 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration