2016-07-26 1 views
1
내가 주문하려는 내 폴더에있는 파일의 목록을 가지고

:주문 파일

Rock, World - SongTitle - Interpret.mp3 
Rock, Acoustic, SingerSongwriter - SongTitle2 - Interpret.mp3 
Rock, Acoustic - SongTitle3.mp3 
SingerSongwriter, World - SongTitle4.mp3 

결과를 다음과 같아야합니다

storage/ 
- Rock, World - SongTitle - Interpret.mp3 
- Rock, Acoustic, SingerSongwriter - SongTitle2 - Interpret.mp3 
- Rock, Acoustic - SongTitle3.mp3 
- SingerSongwriter, World - SongTitle4.mp3 
tags/ 
- Rock/ 
    - LINK TO: storage/Rock, World - SongTitle - Interpret.mp3 
    - LINK TO: storage/Rock, Acoustic, SingerSongwriter - SongTitle2 - Interpret.mp3 
    - LINK TO: storage/Rock, Acoustic - SongTitle3.mp3 
- World/ 
    - LINK TO: storage/Rock, World - SongTitle - Interpret.mp3 
    - LINK TO: storage/SingerSongwriter, World - SongTitle4.mp3 
- Acoustic/ 
    - LINK TO: storage/Rock, Acoustic, SingerSongwriter - SongTitle2 - Interpret.mp3 
    - LINK TO: storage/Rock, Acoustic - SongTitle3.mp3 
- SingerSongwriter/ 
    - LINK TO: storage/SingerSongwriter, World - SongTitle4.mp3 
    - LINK TO: storage/SingerSongwriter, World - SongTitle4.mp3 

내가 스크립트를 설명을 그 날 위해 그 처리한다

#!/bin/bash 

mkdir -p tags; 
mkdir -p storage; 

for file in *; do 
     #Grab Tags from the file name 
     tags=$(echo $file | sed 's/ - /\n/g'); # Doesn't work as it should 

     #                # 
     # This is just blind, can't say if it works, but should(TM).. # 
     #                # 

     #Move file to storage folder 
     mv $file storage/$file; 

     #Foreach Tag: 
     while read -r tag; do 
       #Create tag folder if it doesn't exist yet. 
       mkdir -p tags/$tag; 
       #Create Symbolic Link 
       ln -s storage/$file tags/$tag/$file; 
     done <<< $tags; 
done 

질문을 : 어떻게 ADJ해야합니다 내 스크립트가 작동하도록해야합니까? 나는 bash 스크립팅에 약간의 도움이되었으므로 저를 비난하지 마십시오.

+1

'tags = $ (echo $ file | grep -Eo "^ [^ -] *")'? – Aaron

+0

당신이 문자 그대로 'One', 'Two','Three '(사람들이 100으로 움직일 것으로 기대한다면 사람들은 무료로 코드를 작성하지 않을 것입니다 .--) 단어를 정렬한다는 것을 명확하게해야한다고 생각합니다. "Rock", "90s", "Asian"과 같은 "주제 영역 태그"를 의미합니다. ? 행운을 빕니다. – shellter

+0

@shellter 나는'TagOne','TagTwo','TagThree'를 의미했습니다.이 실제 태그는 분명히 실제 태그가 아닙니다. – jeyemgfx

답변

1

작업 후, 이것은 스레드에 대한 제 응답입니다.

#!/bin/bash 

mkdir -p tags; 
mkdir -p storage; 

for file in *; do 

     #Grab Tags from the file name 
     tags=$(echo $file | grep -Eo "^[^-]*" | sed -e 's/, /\n/g'); 

     #                # 
     # This is just blind, can't say if it works, but should(TM).. # 
     #                # 

     #Move file to storage folder 
     mv "$file" "storage/$file"; 

     #Foreach Tag: 
     while read -r tag; do 
       #Create tag folder if it doesn't exist yet. 
       mkdir -p tags/$tag; 
       #Create Symbolic Link 
       ln -s "storage/$file" "tags/$tag/$file"; 
     done <<< "$tags"; 
done