time modification in script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting time modification in script
# 1  
Old 11-20-2009
time modification in script

Hi All..

I have a file with a number of non-unique entries as below:


1243
01:42:29,567 --> 01:42:32,108
blah blah ....
blah blah ..

1244
01:42:32,709 --> 01:42:34,921
blah blah ....

1245
01:42:35,214 --> 01:42:36,533
blah blah ....
blah blah ..
blah blah ....
blah blah ..


Question is: How can I modify these timings in hh:mm:ss format. Say if I need to add/subtract 30 seconds throughout the file.

I tried to start with this:

cat title | grep "\-\-\>" | awk -F"-->" '{print $1 $2}'
00:07:59,651 00:08:00,379
00:08:34,417 00:08:35,518
00:08:36,892 00:08:38,094


cat title | grep "\-\-\>" | awk -F"-->" '{print $1 $2}'

##VARIABLES hour, minute, second:
hour1=`cat title | grep "\-\-\>" | awk -F"-->" '{print $1 $2}' | cut -c 1,2`
hour2=`cat title | grep "\-\-\>" | awk -F"-->" '{print $1 $2}' | cut -c 15,16`

min1=`cat title | grep "\-\-\>" | awk -F"-->" '{print $1 $2}' | cut -c 4,5`
min2=`cat title | grep "\-\-\>" | awk -F"-->" '{print $1 $2}' | cut -c 18,19`

sec1=`cat title | grep "\-\-\>" | awk -F"-->" '{print $1 $2}' | cut -c 7,8`
sec2=`cat title | grep "\-\-\>" | awk -F"-->" '{print $1 $2}' | cut -c 21,22`

secnew1=`expr $sec1 + 30`
echo $secnew1


But got ERROR ALL AROUND
.

AWK or SED preffered.
Or at least provide the logic.

Thanks a lot
# 2  
Old 11-20-2009
I get time using
Code:
awk -F"-->" '/\-\->/{ print $1 }' title  | awk -F, '{ print $1}'

just use a loop and date command to add 30 sec ... it will take care of mins hrs etc ..
# 3  
Old 11-20-2009
So..

INPUT:
01:42:29,567 --> 01:42:32,108

How can I assign values as:
var1=
01:42:29
var2=
01:42:32


# 4  
Old 11-20-2009
Quote:
Originally Posted by UniRock
So..

INPUT:
01:42:29,567 --> 01:42:32,108

How can I assign values as:
var1=
01:42:29
var2=
01:42:32

just say VAR1=$(awk... ) etc ..

---------- Post updated at 03:04 AM ---------- Previous update was at 02:59 AM ----------

For the first part of time
Code:
for file in $( awk -F"-->" '/\-\->/{ print $1 }' title | awk -F, '{ print $1}' ) ; do  echo -n "$file --->"; date --date="1970-01-01 $file JST +30 seconds" +%H:%M:%S; done

for scnd part
Code:
for file in $( awk -F"-->" '/\-\->/{ print $2 }' title | awk -F, '{ print $1}' ) ; do  echo -n "$file --->"; date --date="1970-01-01 $file JST +30 seconds" +%H:%M:%S; done

# 5  
Old 11-20-2009
Thanks for spending your time but....
Below is the message I am getting:

-n 01:42:32 --->
date: illegal option -- -
Usage: date [-u] [+format]
date [-u] [mmddhhmm[[cc]yy]]
date [-a [-]sss.fff]
-n 01:42:34 --->
date: illegal option -- -
Usage: date [-u] [+format]
date [-u] [mmddhhmm[[cc]yy]]
date [-a [-]sss.fff]
-n 01:42:36 --->
date: illegal option -- -
Usage: date [-u] [+format]
date [-u] [mmddhhmm[[cc]yy]]
date [-a [-]sss.fff]


Why do we use below lines:
date --date="1970-01-01 $file JST +30 seconds" +%H:%M:%S
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. OS X (Apple)

[OS X] Last modification time from shell in CCYYMMDDhhmm.ss format

This example shows last mtime from epoch $ stat -f %m somefile 752911565 But would like to see it like that: 199311100606.05 (2 Replies)
Discussion started by: Tribe
2 Replies

2. Shell Programming and Scripting

How to change modification time of file?

Explain it with proper e.g (4 Replies)
Discussion started by: sidpatil
4 Replies

3. Shell Programming and Scripting

Ls ignoring files from their modification time

Hi everyone, I'd like to know if is there a way to list files but ignoring some according to their modification time (or creation, access time, etc.) with the command 'ls' alone. I know the option -I exist, but it seems to only looking in the file name.. Thank you in advance for the... (8 Replies)
Discussion started by: Keyhaku
8 Replies

4. UNIX for Dummies Questions & Answers

Need Modification Time of a file

Hi all, I need the modification time of a file on a particular day say 3 days before. I just don't want the last modification time. I need all the modification times on a particualar day. Is there anyway to do it? Kindly help. Could anyone tell me where the modification time is stored?... (1 Reply)
Discussion started by: vidhyab
1 Replies

5. Shell Programming and Scripting

Find and symbolic link modification time

Hi, I have a directory made up of many symbolic links to folders multiple file systems. I want to return folders modified within the last 50 days, but find is using the link time rather than the target time. find . -type d -mtime -50 Is there a way to either: a) Make a symbolic link... (1 Reply)
Discussion started by: earls
1 Replies

6. Shell Programming and Scripting

File modification time comparison

Hi All, I have two files (given below) each exists under different paths. I want to compare the modification time stamp of file1.txt is lessthan the modification time of file2.txt. month1=`ls -l file1.txt | awk '{ print $6}'` date1=`ls -file1.txt | awk '{ print $7}'` time1=`ls... (1 Reply)
Discussion started by: Arunprasad
1 Replies

7. Shell Programming and Scripting

Archive Files over certain modification time

Environment is cygwin on Windows Server 2003 as I could not think how I would achieve this using Windows tools. What I want ot achieve is the following. I have a Directory D:\Data which contains further subfolders and files. I need to move "files" older than 6 months modification time to... (4 Replies)
Discussion started by: jelloir
4 Replies

8. Shell Programming and Scripting

ls -e to find out File modification time in secs

Hi All, I would like to know the file modification time till seconds in Unix. So I tried ls -e and it worked fine. This Solaris 5.10 -rw-rw-r-- 1 test admin 22 Sep 12 11:01:37 2008 test_message But I am not able to run the same command in SOlaris 5.6 and also in AIX/HP Is there... (3 Replies)
Discussion started by: rahulkav
3 Replies

9. UNIX for Advanced & Expert Users

Diff b/w modification & updated time

Hi All, What is the difference b/w last modification time and last updated time. Thanks Sweta (1 Reply)
Discussion started by: sweta
1 Replies

10. UNIX for Dummies Questions & Answers

File modification time

Does anyone know how to display the time with seconds of when a file was last modified. I can get hour & minutes but would also like seconds. --Running AIX (1 Reply)
Discussion started by: edog
1 Replies
Login or Register to Ask a Question