LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 01-15-2005, 02:56 PM   #1
lazyuser
LQ Newbie
 
Registered: May 2004
Location: US
Distribution: Debian - Sarge
Posts: 15

Rep: Reputation: 0
scripting question


Hello,

I have a question, but do not know how to set it up, so it can be solved.

Lets say you have files, in a dir, named 0020.mpeg, 0030.mpeg, 0040.mpeg,
ex: /home/lazy/movies/1/0020.mpeg
/home/lazy/movies/1/0030.mpeg
However you have about 500 dir. like this.
/home/lazy/movies/2/0020.mpeg
/home/lazy/movies/2/0030.mpeg, How would you be able to get all them, in order (starting from dir 1 to 500), and move them in one dir, and rename them in order. So 0020.mpeg becomes 1.mpeg and so on. Any Insight is appreciated, not looking for a complete answer just any insight on how I would do this.

Thanks
Lazyuser
 
Old 01-15-2005, 03:07 PM   #2
rgiggs
Member
 
Registered: Apr 2004
Location: berkeley, ca
Distribution: slk10, winxp
Posts: 313

Rep: Reputation: 30
i see 2 for loops. here's a pseudocode i can think of:
Code:
NEWDIR="..."
counter = "1"
for each "subdir" under movies
    for each "file" under "subdir"
         mv "file" to NEWDIR/"counter".mpeg
    endfor
endfor
now, you can go to tldp.org and go through their bash tutorial.

edit:
actually, i think this won't work quite the way you want. i think you want the subdirs processed in order like this:
movies/1
movies/2
...
movies/9
movies/10
...

but i believe my pseudocode will do it like this:
movies/1
movies/10
movies/11
movies/12
...
movies/19
movies/100
movies/101
...
movies/2
movies/20
...

Last edited by rgiggs; 01-15-2005 at 03:15 PM.
 
Old 01-15-2005, 03:17 PM   #3
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
You could probably just use a loop:
Code:
#!/bin/bash
IFS="
"
num=1
for file in `find /path/to/files -name "*.mpeg"`;do
 mv "$file" "`dirname $file`/$num.mpeg"
 num=$(($num+1))
done

Last edited by david_ross; 01-15-2005 at 03:19 PM.
 
Old 01-15-2005, 03:22 PM   #4
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 56
I just happen to have something laying around which may get you started. You could experiment with changing ( ls $dir ) to ( ls -R $dir ) ....
You chomd +x test then run the script like this: ./test /home/dir
Code:
#!/bin/sh

usage()
{
        echo "Usage: $0 [directory]"
        exit 1;
}

test -d "$1" || usage

dir="$1"

ls $dir | grep -e "[:alnum:]" | \
while read i ; do
n=$(( $n + 1 ))
j=`echo $i | awk -F. '{print $2}'`
mv -v "$dir/$i" "/tmp/file$n.$j"

if [ $n -lt '10' ]; then
mv "/tmp/file$n.$j" "/tmp/file00$n.$j"

elif [ $n -ge '10' -a $n -lt '100' ]; then
mv "/tmp/file$n.$j" "/tmp/file0$n.$j"

fi

done
find /tmp -type f -name 'file*' -exec mv -v {} $dir \;
 
Old 01-15-2005, 06:20 PM   #5
lazyuser
LQ Newbie
 
Registered: May 2004
Location: US
Distribution: Debian - Sarge
Posts: 15

Original Poster
Rep: Reputation: 0
Hello,

You guys rule.

I used david_ross example, and it worked. Then I issued the comand, find /home/lazyuser/movies/ -name "*.mpeg" -exec mv {} '/home/lazyuser/movies' \;
to move all the files into a dir.
One more question, if anybody can help. I want to combine all the files into one file. I know I can use cat, but everytime I try it it dosen't put the files in order. When I go ls *.* | sort -n, it puts them in order the way I want. How do I get that order into cat. Or is there some software in linux, where I can combine .mpeg files. Again any help would be appericate.

Thanks for the help already.
lazyuser
 
Old 01-15-2005, 07:38 PM   #6
lazyuser
LQ Newbie
 
Registered: May 2004
Location: US
Distribution: Debian - Sarge
Posts: 15

Original Poster
Rep: Reputation: 0
Hello,

Well I used TMPGEnc in windows, and it worked great. I was wondering if there is any util like this in linux.

lazyuser
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
scripting question... Basslord1124 Linux - Networking 2 11-09-2005 05:52 AM
Scripting question mithereal Linux - General 2 09-21-2005 02:02 AM
Scripting question msandford Linux - Newbie 4 09-05-2005 10:23 AM
scripting question gearoid Programming 3 05-26-2004 02:43 PM
Scripting question glock19 Linux - Software 2 09-05-2003 12:45 AM


All times are GMT -5. The time now is 03:13 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration