![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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. |
|
||||
|
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.. |
|
||||
|
with GNUawk
Code:
awk '{ b=gensub(/\[(.+)\].*\[(.+)\]/,"\\1 \\2","g",$0) ;print b }' "file"
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 |
|
||||
|
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 " |
|
||||
|
Quote:
Code:
awk '/text to grep/{ b=gensub(/\[(.+)\].*\[(.+)\]/,"\\1 \\2","g",$0) ;print b }' file
|
|
||||
|
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 | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|