change and replace time stamp


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting change and replace time stamp
# 1  
Old 11-10-2011
change and replace time stamp

Hi,

I want to convert normal time stamp to unix time stamp to a filename.
coz our ssytem will pick depends on unix timestamp format .
the filenames are as shown below fie names are stored in file say temp.txt.

HTML Code:
MLFG2_cDomHTTPstats_SAB15-1_1318482447.dat
MLFG2_cDomHTTPstats_SAB15-1_1318483347.dat
MLFG2_cDomHTTPstats_SAB15-1_13208241057.dat
MLFG2_cDomHTTPstats_SAB2-0_1318383447.dat
MLFG2_cDomHTTPstats_SAB2-0_1318399647.dat
MLFG2_cDomHTTPstats_SAB2-0_1318468047.dat
MLFG2_cDomHTTPstats_SAB2-0_1318481547.dat
MLFG2_cDomHTTPstats_SAB2-0_1318484247.dat
MLFG2_cSubDomHTTPstats_SAB15-1_1318381647.dat
MLFG2_cSubDomHTTPstats_SAB15-1_1318472547.dat
MLFG2_cSubDomHTTPstats_SAB15-1_1318477047.dat
MLFG2_cSubDomHTTPstats_SAB15-1_1318478847.dat

i have variable that converts present time to UNIX time stamp format.

xx=$(date -d "`date`" "+%s")

xx is having presnt unix timestamp value.

now i want replace above file timestamps 1318481547 with newly got timestamp.

i want to do it in loop so that i will get different stamp for each file .

i have done it using awk but its replacing with same timestamp . that i dont want .

Quote:
awk '{ss=substr($1,1,length($1) - 14);aa=substr($1,length($1) - 4,length($1));$1=ss"'$xx'"aa ;print $1}' $work_dir/datafile.out > $work_dir/newfile.out

let me know any way i can put different timestamp for each filename format in the file using loops.


Thanks,
Raghavendra
# 2  
Old 11-10-2011
Is this what you are looking for:
Code:
#!/usr/bin/ksh
IFS='_'
while read m1 m2 m3 m4; do
  mNewTS=$(date -d "`date`" "+%s")
  mNewFN=${m1}'_'${m2}'_'${m3}'_'${mNewTS}'.dat'
done < Inp_File

# 3  
Old 11-10-2011
That's because xx is a shell variable and you have to pass it to awk using its syntax...
Code:
awk -v myvar=$xx '{ss=substr($1,1,length($1) - 14);aa=substr($1,length($1) - 4,length($1));$1=ss myvar aa ;print $1}' $work_dir/datafile.out > $work_dir/newfile.out

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Change date time stamp of existing file

I have a file hello.txt which was created today (today's date timestamp) I wish to change its date timestamp (access, modified, created) to 1 week old i.e one week from now. uname -a SunOS mymac 5.11 11.2 sun4v sparc sun4v Can you please suggest a easy way to do that ? (12 Replies)
Discussion started by: mohtashims
12 Replies

2. Shell Programming and Scripting

Difference between time stamp

Hi All i have a file data like below format A, B 2016-04-14 16:30:00,2016-04-14 16:31:17 2016-04-14 16:40:00,2016-04-14 16:41:10 2016-04-14 16:50:00,2016-04-14 16:50:41 2016-04-14 17:00:00,2016-04-14 17:00:35 2016-04-14 17:10:00,2016-04-14 17:11:48 2016-04-14 17:20:00,2016-04-14 17:20:37 i... (2 Replies)
Discussion started by: Tarak_nath
2 Replies

3. Shell Programming and Scripting

Update time stamp and replace values

Can anyone please assist? I need to grab each line between the lines "HEADER" and "TRAILER" Each line contains two timestamps(Timestamp1) and (Timestamp2). I need to create two variables TIME_SUBSTRCT and TIME_ADD and then recalculate the two timestamps using this logic:... (5 Replies)
Discussion started by: vinus
5 Replies

4. Shell Programming and Scripting

How to change time stamp with touch command?

Hi, I wish to change time stamp of a directory with all its subdirectories and files on server. I am able to find following two ways but want to know which will be the better one. I have not tried anyone of them because I am not sure if it can effect my data: find * -type d -exec touch... (5 Replies)
Discussion started by: bioinfo
5 Replies

5. Solaris

System time and Cron time stamp not matching

On Solaris 10 server the system date won't match with the timestamp on files created by a cron jobs, Please help here is what i get when i check for system date infodba-ie10ux014:/tcpdv1_ie10/tcadmin/bin\n\r-> date Tue Apr 24 15:27:43 GMT 2012at same time i executed a cron job, and checked... (4 Replies)
Discussion started by: karghum
4 Replies

6. Shell Programming and Scripting

How to get time duration between two human readable time stamp in Unix?

Here is two time I have: Jul 12 16:02:01 Jul 13 01:02:01 and how can I do a simple match to get difference between two time which is 09:00:00 Thanks in advance. (3 Replies)
Discussion started by: ford99
3 Replies

7. Shell Programming and Scripting

regarding time stamp

hi everyone i am facing a strange problem here suppose content of my file is a=1,2,3 b=2,3,4 c=4,5,6 time= now the problem is i want to add value in front of time variable and the value should be i format only "HHMMSS" so it should be like this a=1,2,3 b=2,3,4 c=4,5,6... (3 Replies)
Discussion started by: aishsimplesweet
3 Replies

8. Shell Programming and Scripting

Change time stamp of a file

Hi, As i know , we can change the time stamp of a file by touch command, i did change in a file and it is looking as given # ls -l abcd -rw-r--r-- 1 batsoqa sicusers 0 Feb 17 2010 abcd actually i want to see the output like this -rw-r--r-- 1 batsoqa sicusers ... (3 Replies)
Discussion started by: apskaushik
3 Replies

9. Shell Programming and Scripting

Time stamp calculation

Hi all; I'm relatively new to scripting,I am working on a monitoring script.....where in i have to write subroutine which does the follows: It will check the time stamp of a file ( Oracle remarchive files) and compare it with existing time.If the time difference happen to be more than 90... (6 Replies)
Discussion started by: maverick_here
6 Replies

10. Shell Programming and Scripting

change the time stamp of file

can we change the timestamp of a file to old date. -rwxrwxrwx 1 root other 330 Jul 1 16:03 abc.txt it shows creation time is 16.03 can i change it to previous time :) (2 Replies)
Discussion started by: anish19
2 Replies
Login or Register to Ask a Question