![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Quote:
the last --> [ ! -d $dir ] && mkdir -p $dir && mv $i $dir <-- wouldnt actually move the file if the directory existed already, so I added an extra line below with just --> mv $i $dir <-- in place and that solved that part, so it now becomes, although I would imagine this will now generate an error if the directory it wants to create doesnt exist (but shouldnt error for subsequent files - I think) Code:
#!/bin/bash -x for i in *.jpg do # yy is $1, mm is $2, dd is $3, hh is $4 set -- `echo $i | sed -e 's/\([0-9][0-9]\)/\1 /g'` dir="$1/$2/$3/$4" [ ! -d $dir ] && mkdir -p $dir && mv $i $dir mv $i $dir done |
|
||||
|
Quote:
Instead of a single directory 08072511 I need them nested like >08 ->07 -->25 --->11 |
|
||||
|
I was trying to be 'smart', too many 'short circuit' make me short circuit too.
it should look like this: Code:
for i in *.jpg do # yy is $1, mm is $2, dd is $3, hh is $4 set -- `echo $i | sed -e 's/\([0-9][0-9]\)/\1 /g'` dir="$1/$2/$3/$4" [ ! -d $dir ] && mkdir -p $dir mv $i $dir done Code:
for i in [0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].jpg do ... As for danmero contribution, I couldn't get it working in Solaris bash Code:
$ i=090807060504.jpg
$ d=${i:0:8}
bad substitution
$ echo $SHELL
/bin/bash
$ uname -a
SunOS chihung 5.10 Generic_118833-36 sun4u sparc SUNW,UltraSPARC-IIi-cEngine
Code:
$ i=090807060504.jpg
$ d=${i:0:8}
$ echo $d
09080706
$ uname -a
CYGWIN_NT-5.1 chihung 1.5.25(0.156/4/2) 2007-12-14 19:21 i686 Cygwin
|
|
||||
|
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
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.. |