Sponsored Content
Top Forums Shell Programming and Scripting Script to order my video library :-) Post 302850997 by Don Cragun on Friday 6th of September 2013 08:07:08 AM
Old 09-06-2013
I tested the following using both ksh and bash on Mac OS X even with files named Marvel's Agents of S.H.I.E.L.D..mkv and Marvel's Agents of S.H.I.E.L.D..jpeg and it did what I expected. Having quotes, multiple periods, and spaces in the name seemed like a reasonable test for things you're likely to encounter:
Code:
#!/bin/ksh
for i in *.*
do      if [ ! -f "$i" ]        # Verify that we have a regular file...
        then    continue        # if not; skip to next file.
        fi
        dir=${i%.*}             # Strip off the final filename extension.
        if [ ! -d "$dir" ]      # If the target directory is not present...
        then    mkdir "$dir"    # create it.
        fi
        mv "$i" "$dir"          # Move the file into the appropriate directory.
done

As written this would move the above two mentioned files and Marvel's Agents of S.H.I.E.L.D..txt into a directory named Marvel's Agents of S.H.I.E.L.D.. If you really don't want to move *.txt files into the directory with the assoiated movies with the same base name, change the line in the script:
Code:
for i in *.*

to
Code:
for i in *.flc *.mkv *.avi *.mpg

and add any other filename extensions you want to be processed to the list in the same way. You can put echo in front of the mkdir and mv commands to visually verify that it will do what you want; but, obviously, it won't actually create the directories or move the files as long as those echo commands remain in your script.

Note that this script (and yours) will fail if you have a text file named movie and a file such as movie.mkv because if won't be able to create the directory named "movie" if you already have another file with that name.
This User Gave Thanks to Don Cragun For This Post:
 

6 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Changing the order of columns in a script

I have the following script: (echo -n `curl http://www.example.com/scores.txt | grep mylocation`; date +%Y%m%d%H%M%S) >> myscores.txt This script works fine, except that it places the timestamp at the end of the file myscores.txt. How do add the timestamp as the first column and then a tab and... (4 Replies)
Discussion started by: figaro
4 Replies

2. Linux

USB video capture? composite, s-video, etc

does anybody have any experience with any of these composite video to usb devices on linux? usb video capture - Google Product Search would like to get one but a linux newbie and having trouble figuring out if any are ported... i've found lots of things that link to freedesktop.org DisplayLink... (1 Reply)
Discussion started by: danpaluska
1 Replies

3. UNIX for Advanced & Expert Users

Video Cards :: Video Memory Intercept and Redirect

I need a broad spectrum understanding on this subject, and any help would be greatly appreciated. First of all, as I understand it... The way the video hardware works is the CPU sends information about input and possible changes to the display, the video card receives these changes, makes the... (2 Replies)
Discussion started by: ciNG
2 Replies

4. Shell Programming and Scripting

script for remove descending order number

hi all i want to remove some descending order number example : 1 100 200 135.00 Gk_wirs 1 1 100 200 136.00 Gk_wirs 50 1 110 210 138.00 Gk_wirs 60 1 100 200 136.00 Gk_wirs 57 ----> how to remove... (6 Replies)
Discussion started by: nithyanandan
6 Replies

5. Shell Programming and Scripting

Script to solve second order (polynomial) interpolation

Currently I have awk command to do linear interpolation awk ' { P=$2 I=$1 } END { j=0; s=I; t=I for(i=m;i<=n;i++) { if(I && i>t) { j++; s=I; t=I } print i, P+(i-s)*(P-P)/(t-s) } } ' m=1 n=8 infile FILE CONTENT... (8 Replies)
Discussion started by: Tzeronone
8 Replies

6. Shell Programming and Scripting

Script Execution Order

Hi, I have two scripts which are mentioned in execute.sh more execute.sh ./script1.sh //line 1 should not return error ./script2.sh //line 2 may return error ./script2.sh //line 3 should not return error Condition: I want script1.sh to complete before starting script2.sh... (1 Reply)
Discussion started by: mohtashims
1 Replies
All times are GMT -4. The time now is 01:55 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy