modifying date (-10 hours) in the content of a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting modifying date (-10 hours) in the content of a file
# 1  
Old 10-24-2008
modifying date (-10 hours) in the content of a file

Dear Experts,

I have a problem. I have a file which has contents such as below, with about 500K lines

Code:
34|1|532|2008.10.24 23:41:13|2-1-1-13|90130060128441171|CO0402|0|0x00000201A402000021F6005D4901EC1C2000|0|0|0xE00319FFFFBFFFFE|

with field separator "|", the 4th field is the date (date time), which i need to replace with -10 hours. i need a script urgently to do this. there are multiple files from different days, with each file containing about 500K lines of the above. Please help !

Sara Smilie
# 2  
Old 10-24-2008
What do you mean by "replace with -10 hours" ? Do you mean change the date to one that is 10 hrs prior to the date in the file?
# 3  
Old 10-29-2008
fpmurphy,

yes. i need to change the date to one that is 10 hour prior to the date in the file. Thanks
# 4  
Old 10-30-2008
input(a):
Code:
2008.10.24 23:41:13
2008.10.24 22:41:13
2008.10.24 09:41:13

output:
Code:
2008.10.24 23:41:13
2008.10.24 22:41:13
2008.10.23 23:41:13

code:
Code:
open FH,"<a";
while(<FH>){
        $_=~tr/\n//d;
        $str=rep($_,"H",10);
        print $str,"\n";
}
close FH;
sub rep{
        $time=shift;
        $flag=shift;
        $gap=shift;
        @arr=split("[.| |:]",$time);
        if($flag eq "H"){
                my $temp=$arr[3]-$gap;
                if($temp<0){
                        $arr[3]=$temp+24;
                        $arr[2]-=1;
                }
        }
        if($flag eq "M"){
                my $temp=$arr[4]-$gap;
                if($temp<0){
                        $arr[4]=$temp+60;
                        $arr[3]-=1;
                }
        }
        if($flag eq "S"){
                my $temp=$arr[5]-$gap;
                if($temp<0){
                        $arr[5]=$temp+60;
                        $arr[4]-=1;
                }
        }
        return "$arr[0].$arr[1].$arr[2] $arr[3]:$arr[4]:$arr[5]";
}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert string to date and add 1 hours

i have some set of date data inside csv files and need to convert the timezone, 08302016113611861 08302016113623442 08302016113541570 08302016113557732 08302016113548439 08302016112853115 08302016113620684 08302016113432827 08302016113630321 date format is : %m%d%Y%H%M%Smilisec ... (2 Replies)
Discussion started by: before4
2 Replies

2. Shell Programming and Scripting

Display date from twelve hours ago

HI Guys I want to create date folder in unix base on currant date minus 12 hours. Ex: Currant date :07222013 and time is 1 Am So the folder will create date :07212013 (6 Replies)
Discussion started by: pareshkp
6 Replies

3. Shell Programming and Scripting

Script for moving one file with date content in name

Dear All, I am having a database that generates daily backup files in the below format. abc_date_0010.zip. Can you please suggest a method to copy the last day's file to another location. I am trying with if statement, but having difficulty while I use the condition like if ; then ... (4 Replies)
Discussion started by: skooby
4 Replies

4. Shell Programming and Scripting

Delete log files content older than 30 days and append the lastest date log file date

To delete log files content older than 30 days and append the lastest date log file date in the respective logs I want to write a shell script that deletes all log files content older than 30 days and append the lastest log file date in the respective logs This is my script cd... (2 Replies)
Discussion started by: sreekumarhari
2 Replies

5. UNIX for Dummies Questions & Answers

Adding hours and minutes to current date (Only to date not to time)

Hi, I want to add some hours and minutes to the current date. For example, if the current date is "July 16, 2012 15:20", i want to add 5 hours 30 minutes to "July 16, 2012 00:00" not to "July 16, 2012 15:20". Please help. Thanks! (4 Replies)
Discussion started by: manojgarg
4 Replies

6. Shell Programming and Scripting

Adding hours to current date

Hi, any idea how to add hours to current date in unix. thanks in advance (9 Replies)
Discussion started by: Abhijeet_Atti
9 Replies

7. Shell Programming and Scripting

Grep the Content of a LOG File which has latest Date and Time

Hi All, Need a small help. I have a log file which keeps updating for every Minute with multiple number of lines. I just want to grep few properties which has latest Date and Time to it. How do i do it? I wanted to grep a property by name "Reloading cache with a maximum of" from the... (4 Replies)
Discussion started by: nvindraneel
4 Replies

8. Shell Programming and Scripting

Test if a file has a last modified date of within the last 24 hours

Hi there Im trying to find a way to test whether the last modified time is older than 1 day or not so #!/bin/bash if ; then $TOUCHED = "recently" else $TOUCHED = "not so recently" fi ive seen loads of posts where people are using find and the -mtime property but i... (2 Replies)
Discussion started by: rethink
2 Replies

9. Shell Programming and Scripting

Sort content of text file based on date?

I now have a 230,000+ lines long text file formatted in segments like this: Is there a way to sort this file to have everything in chronological order, based on the date and time in the text? In this example, I would like the result to be: (19 Replies)
Discussion started by: KidCactus
19 Replies

10. Shell Programming and Scripting

how to create file.txt and add current date in file content

Hey guy, how to make bash script to create foo.txt file and add current date into file content and that file always append. example: today the script run and add today date into content foo.txt and tomorrow the script will run and add tomorrow date in content foo.txt without remove today... (3 Replies)
Discussion started by: chenboly
3 Replies
Login or Register to Ask a Question