LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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-28-2008, 02:55 PM   #1
trscookie
Member
 
Registered: Apr 2004
Location: oxford
Distribution: gentoo
Posts: 463

Rep: Reputation: 30
chopping up directories with sed:


Hello all,

I have quite a few music files that I want to move from Win$lows to *nix but they have all been recorded in wma format.

I know how to convert the files from wma to mp3 however because there are quite a lot of files I would like to recursively convert the files, to do this though I will need to list all of the wma's and the directory they are in:

Code:
find . -iname *wma | sed -e 's/\/*\/*.wma//g'`
The command above kind of works but it prints the OP like this:
Code:
./music/Frank Sinatra/20 Classic Tracks/01 Come Fly With Me
./music/Frank Sinatra/20 Classic Tracks/18 Cheek to Cheek
./music/Frank Sinatra/20 Classic Tracks/04 Moonlight in Vermont
./music/Frank Sinatra/20 Classic Tracks/11 Come Dance With Me
./music/Frank Sinatra/20 Classic Tracks/13 Just in Time
./music/Frank Sinatra/20 Classic Tracks/05 Autumn in New York
./music/Frank Sinatra/20 Classic Tracks/09 London by Night
./music/Frank Sinatra/20 Classic Tracks/03 French Foreign Legion
./music/Frank Sinatra/20 Classic Tracks/19 Baubles, Bangles and Beads
./music/Frank Sinatra/20 Classic Tracks/12 Something's Gotta Give
./music/Frank Sinatra/20 Classic Tracks/15 Too Close for Comfort
./music/Frank Sinatra/20 Classic Tracks/16 I Could Have Danced All Night
./music/Frank Sinatra/20 Classic Tracks/14 Dancing in the Dark
./music/Frank Sinatra/20 Classic Tracks/08 Brazil
./music/Frank Sinatra/20 Classic Tracks/02 Around the World
./music/Frank Sinatra/20 Classic Tracks/06 Let's Get Away from It All
./music/Frank Sinatra/20 Classic Tracks/10 It's Nice to Go Trav'ling
./music/Frank Sinatra/20 Classic Tracks/20 Day In - Day Out
./music/Frank Sinatra/20 Classic Tracks/17 Saturday Night (Is the Loneliest Night of the Week)
./music/Frank Sinatra/20 Classic Tracks/07 April in Paris

I would like it to chop the whole filename off and just leave the dir that the files are in.

Thanks, trscookie.
 
Old 02-28-2008, 03:07 PM   #2
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Code:
man basename
and
Code:
man dirname
 
Old 02-28-2008, 03:29 PM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

If you do need to use sed:

Pipe the find command to sed 's%.*/\(.*\)%\1%'

Hope this helps.
 
Old 02-28-2008, 07:59 PM   #4
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Or use bash internal string fiddling:
Code:
find . -iname *wma | sed -e 's/\/*\/*.wma//g'` | while read line ; do
  dir="${line%/*}"
  echo "$dir"
done | uniq
 
Old 02-28-2008, 08:09 PM   #5
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 78
Quote:
Originally Posted by Hko View Post
Or use bash internal string fiddling
Or GNU find using -printf:
Code:
find . -iname *wma -printf '%h\n'
Note that the above is not portable, although this is:
Code:
find . iname *wma -exec dirname '{}' ';'
 
Old 02-28-2008, 08:16 PM   #6
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Quote:
Originally Posted by trscookie View Post
Hello all,

I have quite a few music files that I want to move from Win$lows to *nix but they have all been recorded in wma format.

I know how to convert the files from wma to mp3 however because there are quite a lot of files I would like to recursively convert the files, to do this though I will need to list all of the wma's and the directory they are in:

Code:
find . -iname *wma | sed -e 's/\/*\/*.wma//g'`
The command above kind of works but it prints the OP like this:
Code:
./music/Frank Sinatra/20 Classic Tracks/01 Come Fly With Me
./music/Frank Sinatra/20 Classic Tracks/18 Cheek to Cheek
./music/Frank Sinatra/20 Classic Tracks/04 Moonlight in Vermont
./music/Frank Sinatra/20 Classic Tracks/11 Come Dance With Me
./music/Frank Sinatra/20 Classic Tracks/13 Just in Time
./music/Frank Sinatra/20 Classic Tracks/05 Autumn in New York
./music/Frank Sinatra/20 Classic Tracks/09 London by Night
./music/Frank Sinatra/20 Classic Tracks/03 French Foreign Legion
./music/Frank Sinatra/20 Classic Tracks/19 Baubles, Bangles and Beads
./music/Frank Sinatra/20 Classic Tracks/12 Something's Gotta Give
./music/Frank Sinatra/20 Classic Tracks/15 Too Close for Comfort
./music/Frank Sinatra/20 Classic Tracks/16 I Could Have Danced All Night
./music/Frank Sinatra/20 Classic Tracks/14 Dancing in the Dark
./music/Frank Sinatra/20 Classic Tracks/08 Brazil
./music/Frank Sinatra/20 Classic Tracks/02 Around the World
./music/Frank Sinatra/20 Classic Tracks/06 Let's Get Away from It All
./music/Frank Sinatra/20 Classic Tracks/10 It's Nice to Go Trav'ling
./music/Frank Sinatra/20 Classic Tracks/20 Day In - Day Out
./music/Frank Sinatra/20 Classic Tracks/17 Saturday Night (Is the Loneliest Night of the Week)
./music/Frank Sinatra/20 Classic Tracks/07 April in Paris

I would like it to chop the whole filename off and just leave the dir that the files are in.

Thanks, trscookie.
if you are using GNU find
Code:
find . -iname "*.wma" -printf "%f\n"
Code:
find . -iname "*.wma" | while read -r f
do
 echo ${f%/*}
done
 
Old 02-29-2008, 02:53 AM   #7
trscookie
Member
 
Registered: Apr 2004
Location: oxford
Distribution: gentoo
Posts: 463

Original Poster
Rep: Reputation: 30
wow thank you all for the replies, I am just about to go on a converting rampage!!! trscookie.
 
Old 02-29-2008, 03:20 AM   #8
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
Hope you realize that you can still run .wma on Linux.
 
Old 02-29-2008, 03:22 AM   #9
trscookie
Member
 
Registered: Apr 2004
Location: oxford
Distribution: gentoo
Posts: 463

Original Poster
Rep: Reputation: 30
yea I know you can run them, but it doesnt allow you to burn them to disk and doesnt like you moving them to your Ipod either, they are just a PITA.
 
  


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
getting a sedache when chopping the end off a line: trscookie Programming 2 01-31-2008 05:12 AM
Difference between FTP payload Data and simply chopping a file into payload size ahm_irf Programming 1 11-07-2007 08:58 AM
firefox preferences window chopping off info aisling Linux - Software 1 11-23-2006 10:55 AM
Sound chopping when switching windows Lord_Grave Linux - Hardware 2 01-18-2006 06:43 PM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM

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

All times are GMT -5. The time now is 07:49 PM.

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