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
creating directories on the same box vivek_damodaran HP-UX 3 11-14-2007 03:06 PM
Tar and moving directories stocksj SUN Solaris 2 11-13-2007 11:33 AM
moving directories to new directories on multiple servers mackdaddy07 Shell Programming and Scripting 0 04-06-2007 11:30 AM
bash/awk scripting help (creating OLD new users) Jukai Shell Programming and Scripting 2 10-17-2006 05:36 AM
creating directories carlvernon UNIX for Dummies Questions & Answers 3 06-01-2006 01:45 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-24-2008
Kiint Kiint is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 6
Well, its working (for those out there that stumble across this site for a similar script)

Its not elegant, sane or other ... but it works.

If the better experienced here can clean it up and solve the elegant/sane issues then it would be great

Code:
#!/bin/bash -x

for file in *.jpg; do

YY=`echo $file | awk '{split($0,a,""); print a[1]a[2]}'`
MM=`echo $file | awk '{split($0,a,""); print a[3]a[4]}'`
DD=`echo $file | awk '{split($0,a,""); print a[5]a[6]}'`
HH=`echo $file | awk '{split($0,a,""); print a[7]a[8]}'`

if [ -d $YY ]
then
        if [ -d $YY/$MM ]
        then
                if [ -d $YY/$MM/$DD ]
                then
                        if [ -d $YY/$MM/$DD/$HH ]
                        then
                                mv $YY$MM$DD$HH*.jpg $YY/$MM/$DD/$HH
                        else
                                mkdir $YY/$MM/$DD/$HH
                        fi
                else
                        mkdir $YY/$MM/$DD
                fi
        else
                mkdir $YY/$MM
        fi
else
        mkdir $YY
fi

done
  #2 (permalink)  
Old 07-24-2008
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,420
Shorther:
Code:
for i in *.jpg;do d=${i:0:8};test -d $d || mkdir $d ;mv $i $d;done
  #3 (permalink)  
Old 07-24-2008
Kiint Kiint is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 6
Quote:
Originally Posted by danmero View Post
Shorther:
Code:
for i in *.jpg;do d=${i:0:8};test -d $d || mkdir $d ;mv $i $d;done
Awesome single line version, perfect except the lack of nested directories.

Instead of a single directory 08072511 I need them nested like

>08
->07
-->25
--->11
  #4 (permalink)  
Old 07-24-2008
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,407
Try...
Code:
for i in *.jpg; do d=$(echo $i|cut -c-8|fold -2|paste -s -d /); mkdir -p $d; mv $i $d; done
  #5 (permalink)  
Old 07-24-2008
danmero danmero is offline Forum Advisor  
  
 

Join Date: Nov 2007
Location: 45.48-73.63
Posts: 1,420
Ops, fast reading
Code:
for i in *.jpg;do d=.$(sed 's/\(..\)/\/\1/g' <<< ${i:0:8});test -d $d || mkdir -p $d ;mv $i $d;done
@chihung
Code:
$ uname -a
Linux test 2.6.18-6-686 #1 SMP Sun Feb 10 22:11:31 UTC 2008 i686 GNU/Linux

Last edited by danmero; 07-24-2008 at 10:22 PM..
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 11:59 AM.


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