- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: convert filenames
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
Discussions
Discussions
Forums
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
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
тАО12-07-2006 10:08 PM
тАО12-07-2006 10:08 PM
I have some files with date in filename. Now I#ve to convert the date format in the filename from DD.MM.YYYY to YYYYMMDD.
Sample:
original filename is: BA_D07.12.2006.txt
after converting it should be: BA_D20061207.txt
Can anyone help me? I've no idea how to do.
kind regards
Christian
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-07-2006 10:23 PM
тАО12-07-2006 10:23 PM
Solutiona bit more info required, such as fix format ?
Otherwise:
file="BA_D05.12.2006.txt"
new_file=`echo $file | cut -c 1-4``echo $file | cut -c11-14``echo $file | cut -c8-9``echo $file | cut -c5-6``echo $file | cut -c15-`
echo $new_file
BA_D20061205.txt
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-07-2006 10:24 PM
тАО12-07-2006 10:24 PM
Re: convert filenames
for file in BA_D??.??.????.txt; do
echo mv $file $(echo $file | \
sed -e 's/BA_D\(..\)\.\(..\)\.\(....\)/BA_D\3\2\1/')
done
Remove the "echo" above when you are sure that the mv commands are proper.
The for-loop uses shell pattern matching regexp(5). sed uses basic regular expressions regexp(5).
\( and \) bracket chunks that can be referenced by \#, their position. And I need to quote the "." since they are special.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-07-2006 10:55 PM
тАО12-07-2006 10:55 PM
Re: convert filenames
It's a very strange script but it works fine ;-)
Thanks a lot!!!!
kind regards
Christian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-07-2006 10:59 PM
тАО12-07-2006 10:59 PM