LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-12-2008, 05:32 AM   #1
extasic
LQ Newbie
 
Registered: Oct 2008
Posts: 7

Rep: Reputation: 0
Question Shell Script to copy and number files


Hi!

I need to copy several files from a directory tree. Inside this tree there are several files with the same name, and I have to copy them altogether to the same directory.

This is an example of how it looks

\tmp\a
\tmp\a\1.txt
\tmp\a\2.txt
\tmp\a\3.txt
\tmp\b
\tmp\b\1.txt
\tmp\b\3.txt
\tmp\b\4.txt
\tmp\c
\tmp\c\5.txt
\tmp\c\2.txt

Now I want to copy the files to \tmp\dest1\ as

1.txt, 2.txt .. 8.txt - numbered no matter how they are originally named. I just want to keep the original file extension (that may differ).

How do I realize that?

Thank you in advance!
 
Old 12-12-2008, 06:29 AM   #2
jcookeman
Member
 
Registered: Jul 2003
Location: London, UK
Distribution: FreeBSD, OpenSuse, Ubuntu, RHEL
Posts: 417

Rep: Reputation: 33
If you absolutely don't care about the original file name, then you can do something like this:

Code:
declare -i I=1
find $FILEPATH -regex .*/[0-9]+\.txt -print | while read FILE
do
    mv $FILE $NEWPATH/$I.txt
    let I=$I+1
done
 
  


Reply

Tags
command, find


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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I compare floating number in a shell script? abefroman Programming 29 09-10-2012 11:29 AM
copy directories and files recursively using C shell or bash shell bostonuser Programming 7 06-06-2008 01:24 AM
Which data copy tool is the best if number of files are more. ssrameez Linux - General 2 02-05-2008 10:01 PM
Generate a random number from a bourne shell script lothario Linux - Software 2 03-01-2007 11:01 PM
Shell-script question about getting a number as a variable stormrider_may Programming 9 03-14-2006 08:18 AM


All times are GMT -5. The time now is 11:10 PM.

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