Sorting script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sorting script
# 1  
Old 07-09-2014
Sorting script

Need help with script i have about 40TB of a files *.mov
an need to sort them to folders
i did managed to create some kind of a script to sort new files according to date.
Code:
#! /bin/bash
cd /Volumes/xsan/ARHIVA/SNIMANJA/
mkdir $(date +%Y) #godina
cd $(date +%Y)
mkdir $(date +%B)
cd $(date +%B)
mkdir $(date +%d)
mv /Volumes/xsan/ARHIVA/SNIMANJA/XDCAM_IN/[^"InProgres"]* /Volumes/xsan/ARHIVA/SNIMANJA/$(date +%Y)/$(date +%B)/$(date +%d)

Now i need to do that with all files from /Volumes/xsan/old
to /Volumes/xsan/new
so if i have file 85000.mov in folder "old" and that file is created 2013.05.13. i want to to be moved to /Volumes/xsan/new/2013/05/13

so from this
/Volumes/xsan/old/85000.mov
mv
/Volumes/xsan/new/2013/05/13/85000.mov

Last edited by vbe; 07-09-2014 at 12:34 PM.. Reason: code tags - Not ICODE... thanks
# 2  
Old 07-09-2014
Code:
find /Volumes/xsan/ARHIVA/SNIMANJA/XDCAM_IN/ -type f -printf "%CY/%Cm/%Cd\t%p\n"  |
while read -r DATE FILE
do
        mkdir -p /path/to/"$DATE"
        echo mv "$FILE" /path/to/"$DATE"
done

Remove the echo once you've tested it and are sure it does what you want.

I'm not quite sure what you're doing with that "[^"InProgres"]*", explain and I can add the filter for that.

Last edited by Corona688; 07-09-2014 at 01:16 PM..
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 07-10-2014
Not working says:
HTML Code:
find: -printf: unknown primary or operator

and [^"InProgres"] is to skip files that have "InProgres" in name.
Thanks

---------- Post updated at 08:23 AM ---------- Previous update was at 03:32 AM ----------

i forgot to say that i am using OS X 10.9.
I have found that find those not work on osx and that i should use awk.
Thanks in advance
# 4  
Old 07-10-2014
does the file names have YYYY-MM-DD on them?? Or the directory has only files for one day?
# 5  
Old 07-10-2014
Ok, i have installed macports and findutils and there is no error, but all files are moved in /2014/07/09
and they are not created on that day.

script need to create folder from creation day of a specific file

created filename new location
6/28/14 85729.mov -> /2014/06/28/85729.mov
7/1/14 85764.mov -> /2014/07/01/85764.mov
7/2/14 85797.mov -> /2014/07/02/85797.mov

---------- Post updated at 09:05 AM ---------- Previous update was at 09:04 AM ----------

Files does have YYY-MM-DD

---------- Post updated at 10:14 AM ---------- Previous update was at 09:05 AM ----------

I have managed to do it myself thank you all
here is if someone will need it
Code:
#!/bin/bash
srcdir="/source/dir"
destdir="/destination/dir"

cd $srcdir

touch /tmp/sort.txt
ls -Tl *.mp4 > /tmp/sort.txt

while read line
do
    filename=$(echo $line | awk '{print $10}')
    fileyear=$(echo $line | awk '{print $9}')
	filemont=$(echo $line | awk '{print $6}')
    filedate=$(echo $line | awk '{print $7}')
	filedir=${filedate:0:7}
	filedirm=${filemont:0:7}
	filediry=${fileyear:0:7}
    if [ ! -d $destdir/$fileyear/$filedirm/$filedir ]; then
        mkdir -p $destdir/$fileyear/$filedirm/$filedir
    fi
    # move files 
     if [ ! -f $destdir/$fileyear/$filedirm/$filedir/$fiename ]; then
         mv $filename $destdir/$fileyear/$filedirm/$filedir
     fi


done < /tmp/sort.txt
rm /tmp/sort.txt

---------- Post updated at 10:31 AM ---------- Previous update was at 10:14 AM ----------

And now i need a little help with file_name
if file name have space "file Name.mov" than it is not '{print $10}' than "file is 10" and "Name is 11" how can I combine that?
# 6  
Old 07-10-2014
use $NF --> Last field of the processing line
This User Gave Thanks to PikK45 For This Post:
# 7  
Old 07-11-2014
Quote:
Originally Posted by PikK45
use $NF --> Last field of the processing line
But this is only for last word in line
so for example if the file is called
brown lazy fox jumped_over.mov
$NF
Code:
mv: rename jumped_over.mov to /Volumes/xsan/ARHIVA/SNIMANJA/2014/test/2/2014/Apr/14/jumped_over.mov: No such file or directory

I have tried and $10 $NF
but in that case
Code:
mv: rename brownjumped_over.mov to /Volumes/xsan/ARHIVA/SNIMANJA/2014/test/2/2014/Apr/14/brownjumped_over.mov: No such file or directory

Tried {print $10,$11,$12,$13,$14,$15}') and this when use echo is "working"
Code:
mv brown lazy fox jumped_over.mov /Volumes/xsan/ARHIVA/SNIMANJA/2014/test/2/2014/Apr/14
mv jumped_over.mov /Volumes/xsan/ARHIVA/SNIMANJA/2014/test/2/2014/Jul/11


but when trie without echo it looks like this
Code:
mv: rename brown to /Volumes/xsan/ARHIVA/SNIMANJA/2014/test/2/2014/Apr/14/brown: No such file or directory
mv: rename lazy to /Volumes/xsan/ARHIVA/SNIMANJA/2014/test/2/2014/Apr/14/lazy: No such file or directory
mv: rename fox to /Volumes/xsan/ARHIVA/SNIMANJA/2014/test/2/2014/Apr/14/fox: No such file or directory
mv: rename jumped_over.mov to /Volumes/xsan/ARHIVA/SNIMANJA/2014/test/2/2014/Jul/11/jumped_over.mov: No such file or directory


Last edited by leveex; 07-11-2014 at 11:37 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Problem with sorting in shell script

Hi, I have the following list: 42A 42AA 42B 42BB 42AAA 42BBB 49A 49AA 49B 49AAA 49BB I need it to be sorted as following: 42A 42B (2 Replies)
Discussion started by: sairamtejaswi
2 Replies

2. Homework & Coursework Questions

Shell Script: Sorting by column using grep/awk

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: You will write a script that will read a tab-separated file that contains the names of all 50 states &... (7 Replies)
Discussion started by: tburns517
7 Replies

3. Shell Programming and Scripting

Sorting lines based on keywords for MySQL script

the thing which i require is very very complex.. i tried hard to find the solution but couldnt.. the thing i need to achieve is say i have a file cat delta.sql CREATE VIEW Austin Etc etc . . . CREATE VIEW Barabara AS SELECT blah blah blah FROM Austin z, Cluster s, Instance i WHERE... (4 Replies)
Discussion started by: vivek d r
4 Replies

4. Shell Programming and Scripting

Multi level sorting script

I want to sort like below Suppose few lines in a file is like this systemid:ABC messagedestination:batchxpr replytoqname: myca systemid:BCD messagedestination:realtime replytoqname: myca systemid:ABC messagedestination:realtime replytoqname: eac systemid: BCD messagedestination:mqonline... (1 Reply)
Discussion started by: srkmish
1 Replies

5. Shell Programming and Scripting

Perl script for sorting out an input

<order>10.08.0</order> <order>11.02.0</order> <order>11.02.1</order> <order>11.02.2</order> <order>11.02.4</order> <order>11.02.5</order> <order>11.02.6</order> <order>11.04.0</order> <order>11.04.1</order> <order>11.04.2</order> ... (2 Replies)
Discussion started by: Tuxidow
2 Replies

6. Shell Programming and Scripting

Bourne Script, sorting and getting average of file

Hi I am trying to get a bourne shell script to sort a file for me. Here is what i currently have: #/bin/sh echo "Name Exam1 Exam2 Exam3 Total Grade" > final.txt awk -f 9.awk grades.txt | sort +4 -5 >> final.txt #BEGIN {printf "Name\tExam1\tExam2\tExam3\tTotal\tGrade";} { ... (12 Replies)
Discussion started by: DualPandas
12 Replies

7. Shell Programming and Scripting

Remove default data hash sorting in perl script?

Hi, I have a datahash with 'n' number of values in perl script. I am writing a xml file from the datahash. I am getting output with sorting(Field sorting). My question is that i don't want any default sorting.whatever i am inserting into datahash it should give same xml file. Any help? ... (0 Replies)
Discussion started by: solo123
0 Replies

8. Shell Programming and Scripting

Sorting Windows Directories using Korn script.

I have a directory called test, which contains multiple sub directories namely TF80A, TF80B, TF80C. I need to sort these directories by name, so in the above case TF80A Is the oldest and TF80C is the latest. Is there a ksh script that would loop through the directories and sort these... (1 Reply)
Discussion started by: amadhani
1 Replies

9. UNIX Desktop Questions & Answers

need unix script for sorting

Hi All, I am new to unix,please help me on the following its urgent I have 2 question 1 question I need a script for following senario I have get some files in directory by using grep i need to sort all files to new files for example (abc.dat --> abc.dat.sort) ex:grep *050508* ... (3 Replies)
Discussion started by: cgreddy2020
3 Replies

10. UNIX for Dummies Questions & Answers

Sorting in a script

Hello, I have a situation where I have filenames with timestamps like abc20060509452313.txt i need the most recent file, and i am using this command in the script: recent_file=`ls ${Location}/$file*| head -1` where $Location is the directory and $file is the base filename like abc. When i... (2 Replies)
Discussion started by: anujairaj
2 Replies
Login or Register to Ask a Question