- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- awk program help
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-12-2006 09:01 PM
тАО06-12-2006 09:01 PM
I have a file with multiple entries of start and finish times:
R1 Stock Started Thu 28 Jul 08:52:00 2005
R1 Stock Finished Thu 28 Jul 08:52:15 2005
I would like to use awk to calculate the amount of time it took for R1 to complete.
A million Thank U's
Solved! Go to Solution.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-12-2006 09:17 PM
тАО06-12-2006 09:17 PM
Re: awk program help
Are these entries consecutive entries or can be anywhere.
e.g. are these entries of type
R1 Stock Started time1
R1 Stock Finished time2
R1 Stock Started time3
R1 Stock Finished time4
R1 Stock Started time5
R1 Stock Finished time6
OR can be
R1 Stock Started time1
R1 Stock Started time3
R1 Stock Finished time2
R1 Stock Finished time4
R1 Stock Started time5
R1 Stock Finished time6
Regards,
Ninad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-12-2006 09:25 PM
тАО06-12-2006 09:25 PM
Re: awk program help
Thanks man
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-12-2006 11:10 PM
тАО06-12-2006 11:10 PM
SolutionOR
There can be start entries mixed with stop entries as mentioned in my examples above. So the stop entry for instance 1 does not necessarily follow on the next immediate line of the start for instance 1 , and it may follow some where down the line after say start entries for instance 2 , 3 etc.
Please can you clarify this .
If it is the 1st case then following should do (replace 1.dat by your filename)
awk '/Started/,/Finished/ {
{if(match($3,"Started") == 1) starttime=$7};getline;
{if(match($3,"Finished") == 1) stoptime=$7}}
{print starttime,stoptime}' 1.dat | while read starttime stoptime
do
time1=$(echo $starttime | tr -s ":" " " | awk '{print (($1*3600)+($2*60)+$3)}')
time2=$(echo $stoptime | tr -s ":" " " | awk '{print (($1*3600)+($2*60)+$3)}')
timeelapsed=$(echo "($time2 - $time1)" | bc)
echo "Time elapsed = $timeelapsed seconds"
done
Regards,
Ninad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-13-2006 12:32 AM
тАО06-13-2006 12:32 AM
Re: awk program help
Thanks for a solution i am pretty sure I will be able to work something out.
I have created the file with the start and stop entries and it goes
R1 Stock Started Thu 28 Jul 08:52:00 2005
R1 Stock Finished Thu 28 Jul 08:52:15 2005
R1 Stock Started Thu 29 Jul 08:52:00 2005
R1 Stock Finished Thu 29 Jul 08:52:27 2005
R1 Stock Started Thu 30 Jul 08:52:00 2005
R1 Stock Finished Thu 30 Jul 08:52:01 2005
I'll let you know my results.
TY
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-13-2006 01:26 AM
тАО06-13-2006 01:26 AM
Re: awk program help
As long as the 'start-finished-start-finished' pattern is upheld, the starttime is always 08:52, and the duration is always <8 minutes, you can use this simple one-liner:
awk '/Finished/{print substr($7,5,1)-2 substr($7,6,3)}'
PCS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-13-2006 03:37 AM
тАО06-13-2006 03:37 AM
Re: awk program help
{if(match($3,"Started") == 1) starttime=$7};getline;
{if(match($3,"Finished") == 1) stoptime=$7}}
{print starttime,stoptime}' 1.dat | while read starttime stoptime
do
time1=$(echo $starttime | tr -s ":" " " | awk '{print (($1*3600)+($2*60)+$3)}')
time2=$(echo $stoptime | tr -s ":" " " | awk '{print (($1*3600)+($2*60)+$3)}')
timeelapsed=$(echo "($time2 - $time1)" | bc)
echo "Time elapsed = $timeelapsed seconds"
done
worked fine for me
Thanks chaps