Subtract time in two line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Subtract time in two line
# 1  
Old 10-30-2017
Hammer & Screwdriver Subtract time in two line

INPUT:

Code:
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.

Last edited by rbatte1; 10-30-2017 at 06:43 AM.. Reason: Added CODE tags
# 2  
Old 10-30-2017
Welcome vivekn,

Firstly, please wrap all code, files, input & output/errors in CODE tags. It makes them far easier to read and preserves spacing for indenting or fixed width data.

I have a few to questions pose in response:-
  • Is this homework/assignment? There are specific forums for these.
  • What have you tried so far?
  • What output/errors do you get?
  • What OS and version are you using?
  • What are your preferred tools? (C, shell, perl, awk, etc.)
  • What logical process have you considered? (to help steer us to follow what you are trying to achieve)
Most importantly, What have you tried so far?

There are probably many ways to achieve most tasks, so giving us an idea of your style and thoughts will help us guide you to an answer most suitable to you so you can adjust it to suit your needs in future.


We're all here to learn and getting the relevant information will help us all.



Kind regards,
Robin
This User Gave Thanks to rbatte1 For This Post:
# 3  
Old 10-30-2017
It on rhel7

---------- Post updated at 07:25 AM ---------- Previous update was at 05:03 AM ----------

Assignment,

Tried some awk command, but no success
# 4  
Old 10-30-2017
Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

Thank You.

The UNIX and Linux Forums.
These 3 Users Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. Shell Programming and Scripting

Script to subtract time stored in a variable

Hello, I am writing a script to find time difference between two timestamp stored in a variable. i have two variable t1=11:48:30 t2=13:13:48 how i can find the difference i.e t2-t1 in seconds. Please help (4 Replies)
Discussion started by: anand2308
4 Replies

4. Shell Programming and Scripting

Subtract two rows (in Time format)

Hello all, I have written sth like this: #!/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... (4 Replies)
Discussion started by: frhling
4 Replies

5. Shell Programming and Scripting

Find the script running time and subtract from sleeptime

HI Guys, I want to find out the script running time and subtract from sleeptime. My Script Below Give me error :- #!/usr/bin/ksh timeout=100 start=$SECONDS sleep 20 end=$SECONDS echo "Time: $((end - start)) " ScTime = $((end - start)) (1 Reply)
Discussion started by: asavaliya
1 Replies

6. 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

7. 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

8. 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

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