![]() |
|
|
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 |
| How to concatenate consecutive lines | shivi707 | UNIX Desktop for Dummies Questions & Answers | 1 | 01-12-2009 09:08 AM |
| need to concatenate two lines if the line doesnt end with quotes | laxmi131 | UNIX for Advanced & Expert Users | 9 | 10-27-2008 07:22 AM |
| concatenate and display 2 lines as 1 with a condition for 2 line ? | vithala | Shell Programming and Scripting | 7 | 07-11-2008 02:01 AM |
| Need solution concatenate and display 2 lines as 1 with a condition for 2 line ? | vithala | UNIX for Advanced & Expert Users | 1 | 07-10-2008 02:27 PM |
| Extracting Logfile Entries | harpdl | Shell Programming and Scripting | 2 | 07-13-2006 02:40 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Logfile - extracting certain lines to concatenate into 1 line
I've got a log file from automatic diagnostic runs. The log file is appended to each time an automatic log is run.
I'd like to just pull certain lines from each run in the log file, and concatenate them into 1 comma delimited line (for export into excel or an html table). Each diagnostic run is bracketed by a begin and end comment so I'm able to group it that way but I'm having trouble getting everything into 1 line. Typical data: Diags begin. Tues March 17 18:07:34 EDT 2009 PASS: (123) Power Check . . [more data] Diags end. Diags begin. Tues March 17 19:09:22 EDT 2009 FAIL: (123) Power Check . description: Voltage clamp . .[more failing data details] . Diags end. I want the timestamp, test result (for the 123 test) I was able to use awk to get close but I can't quite get it. awk '/Diags begin/{getline;print};{if ($2=="(123)") print $1,$2,$3,$4}' This gives me: Mon Mar 16 11:37:07 EDT 2009 PASS: (123) Power Check Mon Mar 16 12:31:10 EDT 2009 PASS: (123) Power Check Tue Mar 17 01:30:54 EDT 2009 **FAIL: (123) Power Check Tue Mar 17 03:08:16 EDT 2009 PASS: (123) Power Check What I'm trying to get is: Mon Mar 16 11:37:07 EDT 2009,PASS: (123) Power Check Mon Mar 16 12:31:10 EDT 2009,PASS: (123) Power Check Tue Mar 17 01:30:54 EDT 2009,**FAIL: (123) Power Check Tue Mar 17 03:08:16 EDT 2009,PASS: (123) Power Check Also, I'm looking for a way to just pull the information for a certain time frame (for instance the current date - 7 days) but I'll worry about that later.. baby steps... ![]() The system is Unix (HP-UX) so awk, perl, or sed are options. Thanks for any help.. Paul |
|
||||
|
#!/usr/bin/perl -w
use strict; open (FH,'txt'); my $fb=0; my @str ; while (my $line = <FH>){ chomp ($line); if ($line =~ m/Diags begin/){ $fb =1; } if ($fb && !($line =~ m/Diags begin/ || $line =~ m/Diags end/ )){ push @str , $line; } if ($line =~ m/Diags end/){ my $x = join " ", @str; print "$x\n"; @str=(); $fb=0; } } Try this Cheers Last edited by daptal; 03-17-2009 at 11:36 PM.. Reason: output |
|
||||
|
ok, thanks for the good ideas.. after some hacking and testing I finally got the output in a workable format using awk.
I've outputted the results to an ascii file in a comma delimited format.. my output file is called tstres.txt and typical lines in the file look like this: TSTR01 , Mar 29 21:29:17 EDT 2009 , PASS: , Power Check TSTR01 , Mar 30 00:54:55 EDT 2009 , PASS: , Power Check TSTR01 , Mar 30 08:31:31 EDT 2009 , **FAIL: , Power Check TSTR02 , Mar 07 14:41:08 EST 2009 , PASS: , Power Check TSTR02 , Mar 07 21:46:33 EST 2009 , PASS: , Power Check What is the easiest way to take this data file and output it to an html table ? My plan is to have the script run in a cron job and all I'll need to do is view the html page. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|