LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 09-21-2009, 01:12 PM   #1
wademac
Member
 
Registered: Apr 2008
Posts: 37

Rep: Reputation: 15
Find and Rename files made by Windoze users


I have a windows user that creates csv files and ftp to a linux server but they never follow any case structure so the file maybe

ABC.csv or Abc.CSV or Abc.CSV etc..

I need to find and rename it to just abc.csv
 
Old 09-21-2009, 01:26 PM   #2
rn_
Member
 
Registered: Jun 2009
Location: Orlando, FL, USA
Distribution: Suse, Redhat
Posts: 127
Blog Entries: 1

Rep: Reputation: 25
Please clarify, is your question on how to find the file, or how to rename the file?

You could use the 'find' (man find) command to find the files. The '-name' parameter can accept wild-cards (eg. '*.[Cc][Ss][Vv]')

and you can use the 'tr' (man tr) command to change the name to lower case (tr [:upper:] [:lower:]).

put these two into a loop or something and you will have a script that renames the file.
 
Old 09-22-2009, 07:33 AM   #3
wademac
Member
 
Registered: Apr 2008
Posts: 37

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by rn_ View Post
Please clarify, is your question on how to find the file, or how to rename the file?

You could use the 'find' (man find) command to find the files. The '-name' parameter can accept wild-cards (eg. '*.[Cc][Ss][Vv]')

and you can use the 'tr' (man tr) command to change the name to lower case (tr [:upper:] [:lower:]).

put these two into a loop or something and you will have a script that renames the file.
The reason I need to find the file first because I dont know the case they upload the file in so a find that will ignore case and change just the file name to lower case

so find -iname file.csv and finds the file FILE.CSV than takes what if fines and runs the found file in a tr command something like

tr -s '[a-z][A-Z]' '[A-Z][a-z]' <FILE.CSV> file.csv

The problem is I not sure how to wrap this into one magic script
 
Old 09-22-2009, 07:43 AM   #4
wademac
Member
 
Registered: Apr 2008
Posts: 37

Original Poster
Rep: Reputation: 15
I think all I need to do is FIND the file and use a move command after it is found!

what do you think?
 
Old 09-22-2009, 08:04 AM   #5
malekmustaq
Senior Member
 
Registered: Dec 2008
Location: /root
Distribution: Slackware & BSD
Posts: 1,206

Rep: Reputation: 230Reputation: 230Reputation: 230
wademac,

yes, if you can find the file you can change its name accordingly.
use "-atime n" switch command of "find" to access newly created file regardless of filename.
use the manual for command "find" to get acquainted to it.
user@host--$: man find

hope this helps.
good luck.
 
Old 09-22-2009, 09:18 AM   #6
rn_
Member
 
Registered: Jun 2009
Location: Orlando, FL, USA
Distribution: Suse, Redhat
Posts: 127
Blog Entries: 1

Rep: Reputation: 25
Quote:
Originally Posted by wademac View Post
The problem is I not sure how to wrap this into one magic script
you're close. i just didn't feel like ruining your fun in finding out for yourself how to do it. lot's of examples out there...

you sure you don't want to try for yourself first? ...


** !!WARNING!! ** spoiler ahead. stop here if you'd rather research it yourself ...



Code:
for fn in `find /dirname -iname '*.csv'`
do
     nfn=`echo $fn | tr [:upper:] [:lower:]`

     #Optional
     # if it's already in lower case, no need to rename
     [[ $fn = $nfn ]] && continue
     #

     echo renaming $fn to $nfn
     mv $fn $nfn
done


HTH.
-RN.
 
  


Reply

Tags
find, rename


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
Find the space for files owned by specific users sahil.jammu Linux - Newbie 15 03-04-2009 01:15 PM
Samba on RHEL4: Windows users unable to rename or delete files seanys Linux - Software 1 02-13-2009 02:41 AM
On NFS, non-root users can move/rename files belonging to root. Stuart Morrow Linux - Server 2 11-05-2007 11:12 AM
Using Fedora Directory to authenticate windoze users strong.s Fedora 0 07-20-2006 11:16 AM
How do I rename users? (RH 9) djs101 Linux - General 10 09-03-2003 05:37 PM


All times are GMT -5. The time now is 07:25 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