Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Concatenate text from multiple lines

Status
Not open for further replies.
Aug 22, 2002
113
FR
Hello,


I’m writing a script that reads the /var/adm/messages file and split its space delimited fields into variables for later processing.
Though most messages in the file are single lined, there are a few that use multiple lines like in the following example:


May 11 17:20:59 myserver unix: WARNING: /pci@6,4000/scsi@3/sd@0,0 (sd75):
May 11 17:20:59 myserver unix: Error for Command: read Error Level: Fatal
May 11 17:20:59 myserver unix: Requested Block: 17 Error Block: 17
May 11 17:20:59 myserver unix: Vendor: SEAGATE Serial Number: 9751U84015
May 11 17:20:59 myserver unix: Sense Key: Media Error
May 11 17:20:59 myserver unix: ASC: 0x14 (<vendor unique code 0x14>), ASCQ: 0x1, FRU: 0x1


How can I concatenate the messages that come after « unix: » from all lines in case the message « WARNING: /pci@ » occurs?

Thanks for all your help.
 
Code:
open FH,"</var/adm/messages";
while (<FH>) {
  ($first, $second)=split /unix:/, $_;
  push @messages, $second;
}
close FH;
HTH
--Paul
 
Using just the data you supplied, this code works. However, this doesn't differentiate between single or multi line errors. If you can just more info from the log, I can fix it.

Code:
my @error;
while (<DATA>) {
	/.*myserver unix: (.*)$/;
	push @error, $1;
}
foreach (@error) { print $_, "\n";}

__DATA__
May 11 17:20:59 myserver unix: WARNING: /pci@6,4000/scsi@3/sd@0,0 (sd75):
May 11 17:20:59 myserver unix:     Error for Command: read                    Error Level: Fatal
May 11 17:20:59 myserver unix:     Requested Block: 17                        Error Block: 17
May 11 17:20:59 myserver unix:     Vendor: SEAGATE                            Serial Number: 9751U84015  
May 11 17:20:59 myserver unix:     Sense Key: Media Error
May 11 17:20:59 myserver unix:     ASC: 0x14 (<vendor unique code 0x14>), ASCQ: 0x1, FRU: 0x1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top