The UNIX and Linux Forums  


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
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

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 03-17-2009
BecTech BecTech is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 2
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
  #2 (permalink)  
Old 03-17-2009
daptal daptal is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 68
#!/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
  #3 (permalink)  
Old 03-18-2009
pmm pmm is offline
Registered User
  
 

Join Date: Dec 2008
Posts: 50
Following on your awk script - use printf:


Code:
awk '/Diags begin/{getline;printf};{if ($2=="(123)") print ","$1,$2,$3,$4}'

  #4 (permalink)  
Old 03-30-2009
BecTech BecTech is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 2
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.
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 09:33 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