Convert filenames with DDMMYYYY to YYYYMMDD


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Convert filenames with DDMMYYYY to YYYYMMDD
# 8  
Old 04-24-2008
Quote:
Originally Posted by vgersh99
sorry - my bad:
Code:
#!/bin/ksh
find . -type f -name '*??_????????_[0-9][0-9]*_*.tar' | nawk -v q="'" -F_ -v OFS='_' '
{
  f=$0
  $3=substr($3,5) substr($3,1,2) substr($3,3,2)
  printf("mv %c%s%c %c%s%c\n", q, f, q, q, $0, q)
}'

This script does not rename the files - it just outputs the 'renaming' commands.
Let's make sure the 'mv' commands are correct.

Looks like maybe I could replace

'*??_????????_
with
'*_*_

Is that correct?

After we're satisfied with that:
Code:
./testScript.sh | sh

Thanks!

One thing, I understand why, but on a couple, the xxx's, weren't the exact same, someone mis-spelled a word in creating the tar file, so is there a way to make this script work so that regardless of what is in front of the MMDDYYYY.

Know any good tutorial sites that I can learn some of this stuff from?
# 9  
Old 04-24-2008
'*??_????????_
with
'*_*_

Should that work?
# 10  
Old 04-24-2008
Quote:
Originally Posted by cbo0485
Thanks!

One thing, I understand why, but on a couple, the xxx's, weren't the exact same, someone mis-spelled a word in creating the tar file, so is there a way to make this script work so that regardless of what is in front of the MMDDYYYY.

Know any good tutorial sites that I can learn some of this stuff from?
I don't what 'spelling' issues you've had, but... you'd probably want the patterns with the underscores to filter out ONLY the files matching the 'underscored' pattern. But once again.... dunno if it'll fit all your 'mispellings':
Code:
find . -type f -name '*_*_[0-9][0-9]*_*.tar'

Check out the FAQs for the reading material.
# 11  
Old 04-24-2008
Yup, it worked.

Final Script:

Code:
#!/bin/ksh
find . -type f -name '*_*_[0-9][0-9]*_*.tar' | awk -v q="'" -F_ -v OFS='_' '
{
  f=$0
  $3=substr($3,5) substr($3,1,2) substr($3,3,2)
  printf("mv %c%s%c %c%s%c\n", q, f, q, q, $0, q)
}'

Thanks for your help. My log files much appreciate your help with organizing them
Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Convert string (YYYYMMDD) format to date in Sun OS

Hi All I need help in converting a string of YYYYMMDD format to date in Sun OS and then find out if the day is a Wednesday or not. The "date -d" option is not working and your help is much appreciated. The date command usage from the operating system we use here is as follows: Thanks, SK (11 Replies)
Discussion started by: SK123
11 Replies

2. Shell Programming and Scripting

Convert string (YYYYMMDD) format to date in Sun OS

Hi All I need help in converting a string of YYYYMMDD format to date in Sun OS and then find out if the day is a Wednesday or not. The "date -d" option is not working and your help is much appreciated. The date command usage from the operating system we use here is as follows: usage: ... (1 Reply)
Discussion started by: SK123
1 Replies

3. Shell Programming and Scripting

Date format to be changed from DDMMYYYY to YYYYMMDD

My requirement is:- there will be files at a location each day with the date format DDMMYYYY. Novawise_Activity_Call_Notes_04022013.txt Novawise_Activity_Inbound_04022013.txt Novawise_Activity_Inbound_05022013.txt Novawise_Activity_Call_Notes_05022013.txt... (8 Replies)
Discussion started by: djrulz123
8 Replies

4. Shell Programming and Scripting

date(ddmmyyyy) sorting

input : 20110730 20110730 20110731 20110731 20110801 20110801 20110801 20110813 20110815 01062011 01062011 OUTPUT : i need to sort this input in such a way so that the latest date comes first. (11 Replies)
Discussion started by: urfrnddpk
11 Replies

5. AIX

Convert time (YYYYMMDD HHMMSS) to UTC

Okay, so let's say we have a string like: 20110105_193345 This represents: January 5th, 2011 = 20110105 24-hour style time 19:33:45 = 193345 Okay, so we have our time. It's January 5th, 2011 at 19:33:45. I want to convert this time from Eastern Time Zone (which it currently is in)... (1 Reply)
Discussion started by: syndex
1 Replies

6. Shell Programming and Scripting

convert date format YYYYMMDD to MM/DD/YYYY

In my shell script i have a variable which stores date in the format of YYYYMMDD. Is there any way to format this value to MM/DD/YYYY. Thanks. (8 Replies)
Discussion started by: nasirgondal
8 Replies

7. Shell Programming and Scripting

Using awk to convert DD-MMM-YY to YYYYMMDD

Hi i need to convert a date in the format DD-Mon-YY to YYYYDDMM Ex : 01-JUL-00 to 20000701 Can anybdy help me with this?? Thanks in advance Shenaz (5 Replies)
Discussion started by: shanu_85
5 Replies

8. Shell Programming and Scripting

How to convert DDMMYYYY to DD MONTH YYYY in Unix

Hi I am having date as a string in DDMMYYYY format(07082008) in a variable say cdate. I want to Convert it into DD Month YYYY format(7 August 2008). Could someone help. Thanks in Advance. (2 Replies)
Discussion started by: rspk_praveen
2 Replies

9. UNIX for Dummies Questions & Answers

how to convert the string YYYYMMDD into YYYY.MM.DD

how to convert the string YYYYMMDD into YYYY.MM.DD Please advice (1 Reply)
Discussion started by: spatra
1 Replies

10. Shell Programming and Scripting

ddmmyyyy to dd-mmm-yy format?

Hi All, Can anyone tell me a simple way of converting a date in ddmmyyyy format to dd-mmm-yy format. For example 17022006 to 17-FEB-06 Thanks in advance Regards, Gaurav (11 Replies)
Discussion started by: gauravgoel
11 Replies
Login or Register to Ask a Question