- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Rename all the files in a directory?
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2003 12:22 PM
06-11-2003 12:22 PM
Our company is preparing some combined financial/sales reports. I sent out a memo last year indicating
that all files are to be placed in a specific directory and be given filenames like "dd-month-yyyy". For example, 01-March-2002, 13-July-2003. Unfortunately, I did not specify that the monthnames should be English month names. You can guess what happened to our submittals from Madrid and Paris. I now have directories with 15-Diciembre-2002 and 01-Julio-2002. Does anybody know of a UNIX utility that will convert the filenames?
Thanks,
Steve
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2003 12:28 PM
06-11-2003 12:28 PM
Re: Rename all the files in a directory?
You can use sed,
write small script that move files
take the orig. name and move to new name
that generated by sed.
examp: sed /Julio/July/
Check the man of sed to understand.
Caesar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2003 12:38 PM
06-11-2003 12:38 PM
SolutionWe can take advantage of the unix LANG settings (specifically LC_TIME).
Do a locale -a and pick a likely suspect. Next,
LC_TIME=yourpick locale LC_TIME - if your monthnames match - this here's your boy. If you already know the LANG settings this ignore this step.
lang=es_ES.iso88591
# my Spanish guess
#
ls mydir | while read DT
do
DT2=$(caljd.sh -O -S "-" -e $(LC_TIME=${lang} caljd.sh -c -e -I -S "-" ${DT}))
echo "${DT} -> ${DT2}"
done
I'll let you do the mv or cp commands from ${DT} to ${DT2} but this should be very close.
I've not tested this but it looks okay to me. This will learn you to carefully craft specifications next time.
Search the forums for caljd.sh and make sure you find version 2.1. Invoke as caljd.sh -u to get a clue as to what is happening.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2003 01:23 PM
06-11-2003 01:23 PM
Re: Rename all the files in a directory?
cd /dir
ls *Julio* > juliolist
then run a script containing:
cat juliolist |while read line
do
DAY=$(echo $line|awk '{FS="-";print $1}')
MONTH=$(echo $line|awk '{FS="-";print $2}')
YEAR=$(echo $line|awk '{FS="-";print $3}')
mv $DAY-$MONTH-$YEAR $DAY-july-$YEAR
done
This would take care of july
modify/repeat for the other 11 months.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2003 02:33 PM
06-11-2003 02:33 PM
Re: Rename all the files in a directory?
Thanks. A. Clay's method worked the first time. I already knew the LANG settings for Madrid and Paris. I don't quite know how it works but the names go in in French and come out in English. I first did an ls to a temporary file then read it. A mv $DT $DT2 did the rest. This was even easier than multiple passes with sed after I looked up all the possible month names.
Thanks to all,
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2003 02:43 PM
06-11-2003 02:43 PM
Re: Rename all the files in a directory?
I noticed that sometimes the files read in are "Julio" , sometimes they are "JULIO", and sometimes they are "julio". Your script converts all of these to the correct version "July". We don't have any filenames that are duplicates but I don't under stand how the month names were matched. That must be some complicated sed.
Thanks again,
Steve
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2003 02:49 PM
06-11-2003 02:49 PM
Re: Rename all the files in a directory?
Actually the matchings was easy. Everything is matched as lowercase. This does indicate a potential problem. If you have 04-Julio-1776 and 04-JULIO-1776 then both will map to 04-July-1776 and the last one wins. As long as there are no case-insensitive duplicates then no worries.
Since you indicated that you have at least 2 languages, I would suggest that you modify your script passing in lang as an argument.
Regards,
Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2003 02:55 PM
06-11-2003 02:55 PM