date and time to display on the terminal


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting date and time to display on the terminal
# 1  
Old 09-04-2007
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  
Old 09-04-2007
its easier if you show how your input file looks like, and also what you expect to see
# 3  
Old 09-04-2007
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 01:35 AM..
# 4  
Old 09-04-2007
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  
Old 09-04-2007
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  
Old 09-04-2007
Quote:
Originally Posted by cesarNZ
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  
Old 09-05-2007
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??
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Display-performance in terminal, bash or python?

Heyas I've been working on my project TUI (Text User Interface) for quite some time now, its a hobby project, so nothing i sit in front of 8hrs/day. Since the only 'real' programming language i knw is Visual Basic, based upon early steps with MS-Batch files. When i 'joined' linux 3 years ago,... (7 Replies)
Discussion started by: sea
7 Replies

2. UNIX for Dummies Questions & Answers

Display Date and Time in GDB

In gdb is there any way we can display date/time in first column while debugging or is there any command which will print date/time? I am asking this just to know when exactly a breakpoint got hit. (6 Replies)
Discussion started by: rupeshkp728
6 Replies

3. Shell Programming and Scripting

Display files created on particular date & time

Hi , I have BASH system & i am trying to display the files created on a particular date and time, and after displaying those files I also want to delete all those files.Can anyone of you help me out for this............. Thanx Original post contents restored... Please do not erase the question... (3 Replies)
Discussion started by: rakeshtomar82
3 Replies

4. Shell Programming and Scripting

How to display message when starting a terminal

Hello all, I would like a message to be displayed on the shell when someone opens up the terminal - something like a welcome msg with date and time. I know how to do this by running the shell commands but dont know how to display it when a user opens up the terminal? Thanks in advance (27 Replies)
Discussion started by: mrudula009
27 Replies

5. UNIX for Dummies Questions & Answers

How to always display date/time regardless of directory?

I found via Google a way to show the date and time stamp once I log in. However, whenever I cd to another directory it doesn't display the correct path. Here are the relevant parts from my .kshrc : unset _h _m _s eval $(date "+_h=%H ;_m=%M ;_s=%S") ((SECONDS =... (3 Replies)
Discussion started by: Mike F.
3 Replies

6. AIX

Unable to display the date-time in seconds on AIX

Hi, In unix the command "date +%s" displays the date-time in seconds since â00:00:00 1970-01-01 UTCâ (a GNU extension) when executed on unix: -sh-2.05b$ date +%s 1152092690 I tried with all the format control output but unable to display the date-time in seconds i,e as in unix format. Can... (6 Replies)
Discussion started by: me_haroon
6 Replies

7. Solaris

display date n Time

Hi Friends, Can any one guide me regarding 'Display the date and time' command other than the command 'date' thanks n regards SsRrIi (1 Reply)
Discussion started by: SsRrIi
1 Replies

8. UNIX for Advanced & Expert Users

Understanding terminal display of (awkward) characters

Gurus, I've been on computers for a while, but I've yet to have the behind-the-scenes knowledge. I'm not sure if this is so much a Unix question as it is a nitty gritty computer one. We received a customer file which had a "funny apostrophe." When displaying the file via more, the character... (1 Reply)
Discussion started by: effigy
1 Replies

9. UNIX for Dummies Questions & Answers

terminal display

I want to display a system warning message at the prompt of every live terminal on a sun solaris 8 machine using CDE. I know this can be done on a console, but what about dtterm and xterm regular windows? Does anyone know how this is done? What about a single terminal? Clear skies,... (2 Replies)
Discussion started by: seismic_willy
2 Replies

10. UNIX for Dummies Questions & Answers

Script to display last login date/time?

I was wondering if anyone had a script that would display the last time a user logged into a particular machine. I know about the "last" command, but it gives too much info.... I just wanted to know the last time a user used his/her id. ANy help would be greatly appreciated. Ryan (3 Replies)
Discussion started by: ryaneverett5
3 Replies
Login or Register to Ask a Question