The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Sorting : satyam_sat Shell Programming and Scripting 3 04-15-2008 01:30 PM
Sorting in C++.. ronix007 High Level Programming 6 03-06-2008 05:16 PM
regarding file sorting phani_sree High Level Programming 1 02-02-2007 03:04 PM
sorting in awk mahabunta Shell Programming and Scripting 3 01-31-2007 01:56 AM
awk sorting Jaken Shell Programming and Scripting 4 05-21-2006 10:54 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-11-2005
penguin-friend's Avatar
penguin-friend penguin-friend is offline
Registered User
  
 

Join Date: Nov 2001
Location: Paris, France
Posts: 55
Wink Sorting mp3

Hi all...

Here's my question:
-> considering i've got thousands of mp3s', named like "Artist name - Track Name", how could i write a shell (ksh, or bash my favorite, not knowinf enough any other language) that would create a directory (if not existing already) with the Artist's name, and move the corresponding files in it?
i've gave it a try with awk, but i can't get by the spaces in artists's name/track name...
And yes, another thing as soon as there are more than 2 songs of a same artist, create the directory..

Any suggestions would help!! A complet script would be ok, but help to build my one will be fine too!

Thanx all..


Jason

Last edited by penguin-friend; 05-11-2005 at 12:27 PM..
  #2 (permalink)  
Old 05-12-2005
RishiPahuja's Avatar
RishiPahuja RishiPahuja is offline
Registered User
  
 

Join Date: Apr 2005
Location: Bangalore, India
Posts: 203
Cool

I have not tested this...

See this if it works for you

################################################

#!/usr/bin/ksh

MP3DIR="where your mp3 resides"

ls -1 $MP3 > tmpfile
awk -F"-" '{ print $1 }' tmpfile > tmpfile1
uniq tmpfile1 > tmpfile2

while read LINE
do
count=`find $MP3DIR -name "*$LINE*" -print | wc -l`
if [ $count -gt 1 ]; then
mkdir $MP3DIR/$LINE > /dev/null
mv $LINE* $MP3DIR/$LINE
fi
done < tmpfile2

rm -f tmpfile*

################################################
  #3 (permalink)  
Old 05-12-2005
penguin-friend's Avatar
penguin-friend penguin-friend is offline
Registered User
  
 

Join Date: Nov 2001
Location: Paris, France
Posts: 55
Yep!

Thanx it seems to work!
I tested the first part (ie before the while loop), and that worked.
I didn't think of using tmp files, i tried to awk with the same options, working directly on the output of a ls -1:
ls -1 *.mp3 | awk -F"-" '{print $1}' as artists names. Any ideas why that won't work?
  #4 (permalink)  
Old 05-13-2005
RishiPahuja's Avatar
RishiPahuja RishiPahuja is offline
Registered User
  
 

Join Date: Apr 2005
Location: Bangalore, India
Posts: 203
Red face

I dont see any reaon why this should not work.

See the sample run.

arfwsp04% ls -ltr
total 32
drwxr-xr-x 2 arbor arboradm 96 Apr 27 02:50 atr
drwxr-xr-x 3 arbor arboradm 96 Apr 27 07:21 atr_prod
-rw-r--r-- 1 arbor arboradm 149 May 11 00:23 data
-rw-r--r-- 1 arbor arboradm 5656 May 12 03:05 da_report
drwxr-xr-x 4 arbor arboradm 4096 May 13 01:25 final
drwxr-xr-x 2 arbor arboradm 96 May 13 01:33 tt
-rw-r--r-- 1 arbor arboradm 0 May 13 03:09 a-1.x
-rw-r--r-- 1 arbor arboradm 0 May 13 03:09 a-2.x
-rw-r--r-- 1 arbor arboradm 0 May 13 03:09 a-3.x
-rw-r--r-- 1 arbor arboradm 0 May 13 03:19 b1-1.x
-rw-r--r-- 1 arbor arboradm 0 May 13 03:19 b1-2.x
arfwsp04% ls -1 | awk -F"-" '{print $1}'
a
a
a
atr
atr_prod
b1
b1
da_report
data
final
tt


You say...you can do away with tempfiles...I will like to know..how will u do that..

Thanks
Rishi
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:36 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0