The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
help me in sending parameters from sqlplus script to unix shell script Hara Shell Programming and Scripting 2 01-29-2008 03:31 PM
Shell Script: want to insert values in database when update script runs ring Shell Programming and Scripting 1 10-25-2007 03:06 AM
here document to automate perl script that call script hogger84 Shell Programming and Scripting 3 10-22-2007 10:15 AM
returning to the parent shell after invoking a script within a script gurukottur Shell Programming and Scripting 5 09-26-2006 07:05 AM
return valuse from child script to parent script borncrazy Shell Programming and Scripting 1 08-20-2004 03:39 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-15-2007
jimbobla jimbobla is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 4
AWK/SED script help

Hi, was hoping someone may be able to help me with a script solution to move one line to another line from my log file:

My log file currently looks like this:
01:21:12:383 Request
01:21:12:639 Response
01:21:12:386 Request
01:21:12:639 Response
01:21:12:389 Request
01:21:12:640 Response
01:21:12:610 Request
01:21:12:646 Response
01:21:12:645 Request
01:21:12:673 Response

I want it to look like this:
01:21:12:383 Request 01:21:12:639 Response
01:21:12:386 Request 01:21:12:639 Response
01:21:12:389 Request 01:21:12:640 Response
01:21:12:610 Request 01:21:12:646 Response
01:21:12:645 Request 01:21:12:673 Response

I'm thinking sed would probably be best for this but so far I cannot seem to get it to work

Any advice would be most welcome..

Cheers, Jim
  #2 (permalink)  
Old 07-15-2007
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,409
Try...
Code:
paste -s -d ' \n' file1
  #3 (permalink)  
Old 07-15-2007
jimbobla jimbobla is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 4
thanks ygor - a nice easy one for you

much appreciated.
  #4 (permalink)  
Old 07-16-2007
reborg's Avatar
reborg reborg is online now Forum Staff  
Administrator
  
 

Join Date: Mar 2005
Location: Ireland
Posts: 4,211
Code:
sed -n 'N;s/\n/ /p' file > newfile
  #5 (permalink)  
Old 07-16-2007
jimbobla jimbobla is offline
Registered User
  
 

Join Date: Jul 2007
Posts: 4
more help required please...

i'm still a bit of a novice here and assumed I would be able to figure this out for myself but could do with some more advice please...

now I have my log file in this format:

01:11:15:423 Request 01:11:15:541 Response
01:11:15:424 Request 01:11:15:514 Response
01:11:15:436 Request 01:11:15:678 Response
01:11:15:516 Request 01:11:15:675 Response

I would like to calculate the total response time in ms by subtracting $1 from $3 and print the result in a new field at the end of each row:

01:11:15:423 Request 01:11:15:541 Response 118

I thought I might be able accomplish this with some sort of awk script but things seem to get complicated (for me) when dealing with the time stamp.

If anyone could advise the best way forward for this I'd really appreciate it.

Jim
  #6 (permalink)  
Old 07-16-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,533
just one of the many ways, you can do hard maths...:
Code:
awk '
	{
		n=split($1,one,":")
		hh=one[1]
		mm=one[2]
		ss=one[3]
		ms=one[4] #i assume its milleseconds?
		m=split($3,three,":")
		....
		...
		#do time maths..convert everything to seconds, 
		result =  result_of_three(secs) - result_of_one(secs)
                
	}
	{ print $0 " " result }
' "file"
  #7 (permalink)  
Old 07-16-2007
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
nawk -f jim.awk myFile.txt

jim.awk:
Code:
BEGIN {
  SEPtime=":"
  multN=split("3600000:60000:1000:1", multA, SEPtime)
}

function t2milsec(time,   tempA, tempN, i, milsec)
{

  tempN=split(time, tempA, SEPtime)
  for(i=1; i<=tempN; i++)
    milsec += (tempA[i] * multA[i])
  return milsec
}

{ print $0, t2milsec($3) - t2milsec($1) }
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:10 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0