Organizing Files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Organizing Files
# 1  
Old 12-10-2010
Organizing Files

Hi,

I'm fairly new at scripting.

I need to write a script that takes files from a source directory puts them in a target directory and sorts them by artist name.

This is what I have so far

Code:
#!/bin/bash

source_dir='/home/tcindy/songs'
target_dir='/home/tcindy/music'

for path in $(grep .mp3 /home/tcindy/songs)
do
        tag=$(tail -c 128 $path)
        song_name=$(echo "$tag" | cut -c 4-33 | sed -r 's/ +$//')
        artist=$(echo "$tag" | cut -c 34-54 | sed -r 's +$//')
        album=$(echo "$tag" | cut 55-128 | sed -r 's +$//')
done

        filename="$artist - $song_name.mp3"
        echo $filename

if [  -n "$artist"  ] && [  -n "$title"  ] && [ -n "$album" ];then
        filename="$track - $title - $album - $artist.mp3";echo $filename
        cp "$F" "$filename"  #renaming the file(copy)
        if [ -d "$target_dir/$artist/$album" ];then    #moving file to the artist folder
        mv "$filename" "$target_dir/$artist/$album"
                else
                        if [ -d "$target_dir/$artist" ];then
                        mkdir "$target_dir/$artist/$album"
                        mv "$filename" "$target_dir/$artist/$album"
                else
                        mkdir "$target_dir/$artist"
                        mkdir "$target_dir/$artist/$album"
                        mv "$filename" "$target_dir/$artist/$album"
               fi

        fi

exit

Any help would be greatly appreciated!!
# 2  
Old 12-10-2010
Hi ,post a sample list of your source files.
# 3  
Old 12-10-2010
  1. You can't post links untill you have at least 5 posts.
  2. Your image shows that you seem to study at Senecac. Seems a lot of students from there are visiting this site lately. Maybe get in contact with them for help.
  3. On that note: Homework has to be posted in a special forum, using special rules. See this example on how to do it, which is incidentally from a student apparently in the same course with the same problem.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Automate splitting of files , scp files as each split completes and combine files on target server

i use the split command to split a one terabyte backup file into 10 chunks of 100 GB each. The files are split one after the other. While the files is being split, I will like to scp the files one after the other as soon as the previous one completes, from server A to Server B. Then on server B ,... (2 Replies)
Discussion started by: malaika
2 Replies

2. Shell Programming and Scripting

Please help me in organizing the data in UNIX

I have an output file in the form Hostname Value1=abc Value2=def Value3=xyz Hostname1 Value1=abc1 Value2=def1 Value3=xyz1 Hostname2 Value1=abc2 Value2=def2 Value3=xyz2 | | | And so on….. I need to export this output into csv so then it should be in format (8 Replies)
Discussion started by: rahul2662
8 Replies

3. Shell Programming and Scripting

Organizing text file by Capital Names (capital word ' ' capital word)

Hi I have a file passwd_exmpl that contains: root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync... (5 Replies)
Discussion started by: eladage
5 Replies

4. Shell Programming and Scripting

help with organizing some non regular text

hey im trying to get the hex diffrences in two files ones called new and the other is named old i want it to phrase into my script, heres how i need the info: input='\x'94 #the new 1 byte hex change offset=00000000 #the 1st offset of the difference patch unset input offset input='\x'34... (5 Replies)
Discussion started by: lewisdenny
5 Replies

5. Programming

Organizing C++ Code

I have three directories CspInterp, FpnInterp and LinInterp. Each directory contains 4 .h and .ccp files describing 4 classes each CspInterp class CspFsInterp1d : public FsInterp1d class CspVsInterp1d : public VsInterp1d class CspFsInterp2d : public FsInterp2d class CspVsInterp2d : public... (10 Replies)
Discussion started by: kristinu
10 Replies

6. Shell Programming and Scripting

Organizing log

Hello, Following are the log of my sms application COMMAND: #tail -30 /var/log/smsd.log | grep Message_id | awk '{print $1,$2,$9}' OUTPUT: 2011-02-21 12:16:20,5, 03218975857, 2011-02-21 12:16:26,5, 03323048252, 2011-02-21 12:16:53,5, 03323048252, 2011-02-21 12:16:59,5,... (1 Reply)
Discussion started by: telnor
1 Replies

7. Shell Programming and Scripting

Organizing a log

I have a bunch of log files generated from a shell script, its all of my facebook friends and if theyre logged in. Each file is a different person. It runs every 5 minutes. The log file is just the date and time, then 1 if theyre logged in or 0 if theyre not. part of one of the files is: Mon Aug... (5 Replies)
Discussion started by: killer54291
5 Replies

8. Shell Programming and Scripting

Help organizing a music directory with sub directories.

Hello all, I used to have a great script and I lost it :( What the script did was searched a directory named say "music" It searched all sub directories for .mp3 files Then placeed all the .mp3's into a directory of the band name It also renamed the .mps "track#, band name, album name" (I... (9 Replies)
Discussion started by: komputersman
9 Replies

9. Shell Programming and Scripting

How to retrieve all the linked script files/ctl files/sql files?

Hi I am going to migrate our datawarehouse system from HP Tru 64 Unix to the Red Hat Linux. Inside the box, it is running around 40 cron jobs; inside each cron job, it is calling other shell script files, and the shell script files may again call other shell script files or ctl files(for... (1 Reply)
Discussion started by: franksubramania
1 Replies
Login or Register to Ask a Question