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
Processing a log file based on date/time input and the date/time on the log file primp Shell Programming and Scripting 4 03-16-2008 11:23 AM
Unable to display the date-time in seconds on AIX me_haroon AIX 6 07-11-2006 09:18 AM
display date n Time SsRrIi SUN Solaris 1 03-16-2006 05:48 AM
terminal display seismic_willy UNIX for Dummies Questions & Answers 2 02-13-2002 02:39 AM
Script to display last login date/time? ryaneverett5 UNIX for Dummies Questions & Answers 3 12-06-2001 05:21 PM

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

Join Date: Sep 2007
Posts: 70
date and time to display on the terminal

hi all,
am trying to 'grep' some text from a log file and use the 'cut' command to read from that line i just grep'ed to extract date/time and response times.

code sniplet i am using is :

grep -i 'text to grep' Out.log |
while read LINE;
do
mydate=$LINE | cut -f1 -d] | cut -f2 -d[ | cut -f1 -dN;
res=$LINE | cut -f2 -d] | cut -f2 -d[;

printf "%-16s %s\n" $mydate $res
done;


the output i want printed to the terminal in the following columns :

date time response


unfortunately this is printing empty values to the terminal.

the cut command i am using works since i echo'ed the output to the terminal. i think the problem is using printf to print since i am new to printf.

any suggestions on what could be wrong ??

thanks in advance,
Cesar.
  #2 (permalink)  
Old 09-04-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,508
its easier if you show how your input file looks like, and also what you expect to see
  #3 (permalink)  
Old 09-04-2007
cesarNZ cesarNZ is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 70
hi,
my input file looks something like this:

[9/4/07 16:03:46:222 NZST] 962cea SystemOut O RESPONSE [224 millis]
[9/4/07 16:04:28:820 NZST] 962cea SystemOut O RESPONSE [127 millis]
[9/4/07 16:05:05:190 NZST] 16e39ea SystemOut O RESPONSE [424 millis]
[9/4/07 16:05:05:466 NZST] 16e39ea SystemOut O RESPONSE [254 millis]
[9/4/07 16:05:42:547 NZST] 660d07 SystemOut O RESPONSE [199 millis]


i wanted to print out the variables under the following columns :

date/time | response
9/4/07 16:05:42:547 | 199

Last edited by cesarNZ; 09-04-2007 at 12:35 AM..
  #4 (permalink)  
Old 09-04-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,508
with GNUawk
Code:
awk '{ b=gensub(/\[(.+)\].*\[(.+)\]/,"\\1 \\2","g",$0) ;print b }' "file"
output:
Code:
# ./test.sh
9/4/07 16:03:46:222 NZST 224 millis
9/4/07 16:04:28:820 NZST 127 millis
9/4/07 16:05:05:190 NZST 424 millis
9/4/07 16:05:05:466 NZST 254 millis
9/4/07 16:05:42:547 NZST 199 millis
  #5 (permalink)  
Old 09-04-2007
cesarNZ cesarNZ is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 70
thanks for the reply, got one more problem. I don't have any write access to this box where i will be running this script so i can't take the grep command i am using and write it out to a file. would something like this work :

awk '{ b=gensub(/\[(.+)\].*\[(.+)\]/,"\\1 \\2","g",$0) ;print b }' "grep -i \'text to grep\' Out.log "
  #6 (permalink)  
Old 09-04-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,508
Quote:
Originally Posted by cesarNZ View Post
thanks for the reply, got one more problem. I don't have any write access to this box where i will be running this script so i can't take the grep command i am using and write it out to a file. would something like this work :

awk '{ b=gensub(/\[(.+)\].*\[(.+)\]/,"\\1 \\2","g",$0) ;print b }' "grep -i \'text to grep\' Out.log "
Code:
awk '/text to grep/{ b=gensub(/\[(.+)\].*\[(.+)\]/,"\\1 \\2","g",$0) ;print b }' file
  #7 (permalink)  
Old 09-04-2007
cesarNZ cesarNZ is offline
Registered User
  
 

Join Date: Sep 2007
Posts: 70
hummm didnt quite work for me, think my version of awk may be the problem but i dont understand awk well enough to say that. Do you know of any good tutorials for awk ?? i tried what you suggested and it gives me an error which looks like :

awk: syntax error near line 1
awk: illegal statement near line 1

possibly the gensub method is causing this problem??
Sponsored Links
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 07:39 AM.


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