Subtract two rows (in Time format)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Subtract two rows (in Time format)
# 1  
Old 11-28-2012
Subtract two rows (in Time format)

Hello all,
I have written sth like this:
Code:
#!/bin/bash
grep -e XXX -e YYYY myfile.log | grep -v ZZZ | awk '{print $1 " " $2 ";" $3 ";" $9 ";" $11}' > myfile.csv
sed -i '1iDate;Time;From;To' myfile.csv

=> it is clear that it converts log to csv and add a header.
Now I want to subtract row B3-B2,B5-B4,... which I mean I want to subtract the times. right now this is my problem Smilie
i hope someone can help me in a easy way! this is my first script.

Thanks

Last edited by Franklin52; 11-28-2012 at 05:02 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 11-28-2012
Can you provide some sample data to work with? If we can see the format the date is in, it becomes easier to see how to accomplish what you are looking for.

A sample of what you want the finished output to look like would also be useful...
# 3  
Old 11-28-2012
My original output file:
Code:
Date      Time                      From                                                        To
Nov 23     03:21:41             XXX:/export/home/b                        /AAA/b
Nov 23      03:23:25           XXX:/export/home/b                         /AAA/b
Nov 23       03:27:29           XXX:/export/home/x                        /AAA/x 
Nov 23       03:28:03            XXX:/export/home/x                       /AAA/x
Nov 23       03:30:41            XXX:/export/home/y                        /AAA/y
Nov 23        03:30:58            XXX:/export/home/y/                       AAA/y

What I want
Code:
Date       Time                   From                                                   To
Nov 23    00:01:44          XXX:/export/home/b                             /AAA/b
Nov 23    00:00:34          XXX:/export/home/x                               AAA/x
Nov 23     00:00:17       XXX:/export/home/y/                                AAA/y


Moderator's Comments:
Mod Comment Video tutorial on how to use code tags in The UNIX and Linux Forums.

Last edited by Franklin52; 11-28-2012 at 06:42 AM.. Reason: Please use code tags for data and code samples
# 4  
Old 11-28-2012
Ok, let me check a few details with you.

XXX, YYY and ZZZ will always be IP addresses, right? You want to map how long it took to copy files from specific remote servers (xxx,yyy) but not others (ZZZ) to a local location.

Will AAA always be the same location or will it vary?

---------- Post updated at 11:03 AM ---------- Previous update was at 10:51 AM ----------

Could you also add an extract from your original source log? It may be more efficient to do all of this in one step, rather than in multiple steps. I'll look at doing it with the data provided as well though.
# 5  
Old 11-28-2012
really Thanks replying fast!
The problem ist I dont know how to attach a file.
I dont see any option! Smilie

Quote:
Originally Posted by spynappels
Ok, let me check a few details with you.

XXX, YYY and ZZZ will always be IP addresses, right?
They are some words.
You want to map how long it took to copy files from specific remote servers (xxx,yyy) but not others (ZZZ) to a local location.
Yes, I want to know how long it takes to copy files from remote servers which is mentioned in FROM.
Will AAA always be the same location or will it vary?
actually for each user it is different.
for user a: AAA, foe user b may be FFF.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Subtract time in two line

INPUT: 16:45:51 10051 77845 16:45:51 10051 77845 16:46:52 10051 77846 16:46:53 10051 77846 Match the last PID then subtract second line time with first line. Please help me with any command or script. (3 Replies)
Discussion started by: vivekn
3 Replies

2. UNIX for Dummies Questions & Answers

How to chnage format and subtract time and date and get average.?

Hello All , Please support for below request how to change format and subtract time and date and get average. xxx 13-OCT-15 11.32.18.241000 AM 13-OCT-15 11.35.49.089080 AM xxx 13-OCT-15 11.32.24.000000 AM 13-OCT-15 11.45.17.810904 AM xxx 13-OCT-15 11.32.25.232000 AM ... (1 Reply)
Discussion started by: mirwasim
1 Replies

3. Shell Programming and Scripting

Date command - subtract from given time

the given time is: 12:13:00 how do i subtract a 10 minutes from any given time? date '12:13:00' '-10 min' also tried this: date +12:13:00 '-10 min' (2 Replies)
Discussion started by: SkySmart
2 Replies

4. Shell Programming and Scripting

Script to subtract rows HELP

Dear All, Please help with a script which can accomplish the following: Input table: $1 $2 $3 Student1 1 50 Student2 56 75 Student3 77 100 Desired Output: $1 $2 $3 $4 Student1 1 50 Student2 56 75 6 Student3 77 ... (4 Replies)
Discussion started by: saint2006
4 Replies

5. Shell Programming and Scripting

How to subtract time by 10 minutes in datecalc tool

Hi guys. I am trying to subtract 10 minutes from the current Unix system date and time. I have the datecalc provided here but it is mainly the date and not the time. Please check on how can i subtract 10 minutes from the current time using datecalc or any other shell scripting that will... (2 Replies)
Discussion started by: bantiloe
2 Replies

6. Shell Programming and Scripting

Add/Subtract Time

need some help on the below requirement: File1: SV,22,20100501140000,JFK,RUH SV,29,20100501073000,BOM,RUH SV,29,20100501073000,SIN,RUH third filed is datetime which is of the format (yyyymmddhh24miss) File2 JFK,+,0500 BLR,-,0530 SIN,-,0800 for every line of file 1, take 4... (9 Replies)
Discussion started by: ssantoshss
9 Replies

7. Shell Programming and Scripting

subtract minutes from time

i have the time 20100421043335 in format (date +%Y%m%d%H%M%S),and i want to be able to get the previous time 2 minutes ago,which is 20100421043135 (9 Replies)
Discussion started by: tomjones
9 Replies

8. Shell Programming and Scripting

Convert Epoch time format to normal date time format in the same file

I have a file named "suspected" with series of line like these : {'protocol': 17, 'service': 'BitTorrent KRPC', 'server': '219.78.120.166', 'client_port': 52044, 'client': '10.64.68.44', 'server_port': 8291, 'time': 1226506312L, 'serverhostname': ''} {'protocol': 17, 'service': 'BitTorrent... (3 Replies)
Discussion started by: rk4k
3 Replies

9. Shell Programming and Scripting

Subtract Time

Hello, Im writing a script using the ksh shell. I have 2 variables in the script: CURRTIME PREVTIME Example, if CURRTIME=13:00, I want to somehow calculate what the time was an hour ago so that PREVTIME=12:00 Right now I have the following: CURRTIME=`date +%H:%M` How can I... (4 Replies)
Discussion started by: xadamz23
4 Replies

10. UNIX for Dummies Questions & Answers

Subtract date & time in diferent rows

Hi Friends :) I have a long file having fields in the form : Field1 yy/mm/dd hh:mm:ss Duration(Sec) line 1) 123123 05/11/30 12:12:56 145 line 2) 145235 05/11/30 12:15:15 30 line 3) 145264 05/11/30 13:14:56 178 . . I want to subtract yy/dd/dd hh:mm:ss in line (2) from yy/mm/dd hh:mm:ss in... (1 Reply)
Discussion started by: vanand420
1 Replies
Login or Register to Ask a Question