Change new filename with date ??


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Change new filename with date ??
# 8  
Old 02-09-2006
Thank you very much , I have learned it from you Smilie
Here is the code if someone want to learn


cd /full/path/to/DATA
for file in Perform*Log; do
newFile=`ls -1 $file|awk -F. '{ \
y = substr($2,5,4); \
m = substr($2,1,2); \
d = substr($2,3,2); \
printf "%s-%s%s%s.dat",tolower($1),y,m,d \
}'`
awk -F\| '{if(NR!=1) print $1"|"$3"|"$4"|"$5}' $file > /full/path/to/NEWDATA/$newFile
done

Thanks again

Last edited by sabercats; 02-10-2006 at 02:20 PM..
# 9  
Old 02-13-2006
Just wonder if we look at the flie

ID|Location|Date|Hostname|Age|Sex
1|SFO|02/06/2006|hawkeye|35|M
2|LAX|02/06/2006|sf49ers|30|M
3|OAK|02/06/2006|goraiders|27|F
4|PIT|02/06/2006|steeler|35|M

The field $3 is date 02/06/2006 and we write the output is file name perform-20060206.dat, its contain
1|02/06/2006|hawkeye|35
2|02/06/2006|sf49ers|30
3|02/06/2006|goraiders|27
4|02/06/2006|steeler|35

Any idea ? I just want to learn with diffrerent way .
Thanks,
# 10  
Old 02-13-2006
Code:
echo '02/06/2006' | nawk '{n=split($1, da, "/"); print da[3] da[1] da[2]}'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to change existing date to current date in a filename?

Suppose i have a list of files in a directory as mentioned below 1. Shankar_04152019_ny.txt 2. Gopi_shan_03122019_mi.txt 3. Siva_mourya_02242019_nd.txt .. . . . . 1000 . Jiva_surya_02282019_nd.txt query : At one shot i want to modify the above all filenames present in one path with... (4 Replies)
Discussion started by: Shankar455
4 Replies

2. Shell Programming and Scripting

How to append date to filename, but base it on yesterday's date?

Hello, I'd like to write a monthly archive script that archives some logs. But I'd like to do it based on yesterday's date. In other words, I'd like to schedule the script to run on the 1st day of each month, but have the archive filename include the previous month instead. Here's what I... (5 Replies)
Discussion started by: nbsparks
5 Replies

3. Shell Programming and Scripting

Change the content of files but not change the date

I have 100 files in a directory , all the files have a word "error" and they are created in different date . Now I would like to change the word from "error" to "warning" , and keep the date of the files ( that means do not change the file creation date after change the word ) , can advise what can... (7 Replies)
Discussion started by: ust3
7 Replies

4. Shell Programming and Scripting

Change the content of files but not change the date

I have 100 files in a directory , all the files have a word "error" and they are created in different date . Now I would like to change the word from "error" to "warning" , and keep the date of the files ( that means do not change the file creation date after change the word ) , can advise what can... (0 Replies)
Discussion started by: ust3
0 Replies

5. UNIX for Dummies Questions & Answers

How to change date in a filename?

Hi i want to list files based on date and change the date alone in the files in a directory abc20120101.txt xyzxyxz20120101.txt ccc20120201.txt ddd20120301.txt In the above i want to select only files having date 20120101 and rename the date for those files like below abc20111231.txt... (3 Replies)
Discussion started by: Dewdrop
3 Replies

6. Shell Programming and Scripting

Change the filename variable value

Hi guys, I have a variable where i am storing the filename (with full path). I just need the value before ".txt". But instead of getting the filename i am getting the contents of the filename. FileName=/appl/data/Input/US/Test.txt a=`awk -F"." '{print $1}' ${FileName}` echo $a... (3 Replies)
Discussion started by: mac4rfree
3 Replies

7. Shell Programming and Scripting

Get the oldest date based on date in the filename

I am using ksh93 on Solaris. Ok, this may seem like a simple request at first. I have a directory that contains sets of files with a YYYYMMDD component to the name, along with other files of different filespecs. something like this: 20110501_1.dat 20110501_2.dat 20110501_3.dat... (2 Replies)
Discussion started by: gary_w
2 Replies

8. Shell Programming and Scripting

Change the filename

I have 100 files in a directory with a.1 a.2 a.3 a.4 How do i remove a. and i need the file names as 1 2 3 4 please help (2 Replies)
Discussion started by: srichunduru
2 Replies

9. Shell Programming and Scripting

gzcat into awk and then change FILENAME and process new FILENAME

I am trying to write a script that prompts users for date and time, then process the gzip file into awk. During the ksh part of the script another file is created and needs to be processed with a different set of pattern matches then I need to combine the two in the end. I'm stuck at the part... (6 Replies)
Discussion started by: timj123
6 Replies

10. UNIX for Dummies Questions & Answers

Move A File With Same Date,don't Change The Desitination Dir Date

Assume, I created one file three years back and I like to move the file to some other directory with the old date (Creation date)? Is it possible? Explain? (1 Reply)
Discussion started by: jee.ku2
1 Replies
Login or Register to Ask a Question