Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing the name on files. 3

Status
Not open for further replies.
May 21, 2004
21
US
I have restored a lot of files from a Linux server and I need to change their naming conventions to a Windows format. Example:

I need to change the Linux file D:\Test\test.doc to test.doc to copy it to a Windows server.

Is there any way to change it in Linux or Windows?

Rowlen
 
Your example is strange; can you give us a better one?

Anyway, it certainly is possible. Something like Perl on either Linux (where it's native) or Windows would certainly do the job. Even the "rename" command (using wildcards) on Windows might be enough.
 
Thanks Tony.

We have restored, from a backup, a large group of files to a Linux server. The files though are Windows files, so when they were restored they were restored as:

"D:\Test\alpha.doc"
"D:\Test\beta.doc"
"D:\Test\zeta.doc"

I need to rename the files to:
alpha.doc
beta.doc
zeta.doc
 
This should do the job:
[tt]
perl -e 'for(<*>){if(/.*\\(.+)/){rename $_,$1}}'
[/tt]
 
Sooooo... it didn't restore them to the proper directories?

That could leave you with BIG problems if you have duplicate filenames (filenames that *would* be duplicated when you removed the path info from the beginning)....

What a headache.

You really need a script that would:

mv "D:\Test\Test.doc" /somedir/Test/Test.doc

... so that it puts them in the correct folders.....



Just my 2¢

"In order to start solving a problem, one must first identify its owner." --Me
--Greg
 
gbaughma said:
Sooooo... it didn't restore them to the proper directories?
No, but your request didn't in any way indicate that they should be restored to proper directories. You said that files should be renamed to what we call their "basenames"; you made no mention of where they should go.

Try this:
Code:
for winname in *; do
    linuxname=$(echo "$winname" |tr '\' '/' |sed 's#^\(.\):#\1#')
    dir=$(dirname $linuxname)
    base=$(basename "$linuxname")
    mkdir -p "$dir"
    mv "$winname" "$dir/$base"
done
 
Chipper - unless I'm mistaken that author of the 'Soooo...' comment isn't the same person as the originator of the thread. I think gbaughma was just pointing out possible pitfalls.
 
Agreed, gporwilson never asked to have the files restored in the correct directories.

From what I understood, he just wants to strip the file name without the windoz path.
Nevertheless chipperMDW offered a valid piece of script.

QatQat

Life is what happens when you are making other plans.
 
Chipper:

That is, in fact, an elegant piece of work. I gave you a star (even though it wasn't my original post).... but very nicely done.



Just my 2¢

"In order to start solving a problem, one must first identify its owner." --Me
--Greg
 
The long version is it is more of a Networker restore problem. Here is the situation:

We are trying to restore, through Networker's uasm command some Windows data. The Networker server is Linux. We mounted the Windows file system in Linux but were unable to recover the files to Windows. We kept getting an error 'uasm: Cannot create <directory name> no such file or directory'

2. We do not have enough space on the Networker server to restore the files locally (26GB), so we USB attached a storage unit. The problem with this is the files are being restored but they have names like a Windows file on Linux. The names are:

-rwx------ 1 root root 0 Apr 30 2001 D:\SERdata\Reports\General\10042801\PAGES1ST.PBP
-rwx------ 1 root root 0 Apr 30 2001 D:\SERdata\Reports\General\10042801\PAGESIX.001
-rwx------ 1 root root 0 Apr 30 2001 D:\SERdata\Reports\General\10042801\PAGES.PBP
-rwx------ 1 root root 0 Apr 30 2001 D:\SERdata\Reports\General\10042801\PLATINFO.PBP
-rwx------ 1 root root 0 Apr 30 2001 D:\SERdata\Reports\General\10042801\PLATX.PBP
-rwx------ 1 root root 0 Apr 30 2001 D:\SERdata\Reports\General\10042801\REPORTS.001

This is going to be a problem because I would have to rename them then try to put each file in the correct directory. So at that time I was going to restore the files with the long names then 'strip' the long names off of the files. But that brings up the problem of putting the files in the correct directory.

Thank you everyone for you insights.
 
I know how to do this with WebSphere TX, but is a bit expensive for this type of work.



BocaBurger
<===========================||////////////////|0
The pen is mightier than the sword, but the sword hurts more!
 
Chipper - unless I'm mistaken that author of the 'Soooo...' comment isn't the same person as the originator of the thread.
Ah, you're right; thanks for pointing that out. My mistake, and apologies to gporwilson and gbaughma for mixing you two up.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top