![]() |
|
|
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 |
| runnning a shell script in multiple folders | melearlin | Shell Programming and Scripting | 2 | 05-19-2009 03:36 AM |
| Shell script to move certain files on scheduled time | abhishek27 | Shell Programming and Scripting | 7 | 05-07-2009 01:09 AM |
| Move folders containing certain files | xavix | UNIX for Dummies Questions & Answers | 3 | 02-21-2009 06:43 AM |
| how to move files into different folders based on filename | italia5 | UNIX for Dummies Questions & Answers | 7 | 08-23-2006 11:04 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
while [ "$COUNTER" != "0" ]
it never reaches 0, so it has nothing left to do but a continuous loop of nothing, you need to break at somepoint It should be in a for loop instead of while. change COUNTER=`ls -1 | wc -l` while [ "$COUNTER" != "0" ] to COUNTER=`ls -1 | wc -l` for (( $i=0; $i < "$COUNTER" ; i++ )); do |
|
||||
|
I solved it!! Thanx for all sighK. This is the code for my script. It is used to move files (in my particular case were tiff images) from a folder to 3 different folders distributing the files among them. For example, if source folder has 100 files, the 3 target folders have to end up with 34, 33 and 33 files respectively. Hope this could be helpful to someone. Code:
#!/bin/bash
COUNTER=`ls -1 *.TIF | wc -l`
while [ $COUNTER -gt 0 ]
do
ARRAY=( $(ls *.TIF | head -n 3) )
mv ${ARRAY[0]} folder1/
mv ${ARRAY[1]} folder2/
mv ${ARRAY[2]} folder3/
COUNTER=`expr $COUNTER - 3`
done
You can change file extension or just delete it, folder paths and of course, the number of folders, just remember to change 'head -n' where n is the number of files to list first that will end up inside each folder. You also have to change the number in `expr $COUNTER - 3` to match the number of folders. |
![]() |
| Bookmarks |
| Tags |
| file, folder, move, script, shell |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|