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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
sed - Replace Line which contains the Pattern match with a new line kousikan Shell Programming and Scripting 2 03-24-2007 04:24 AM
SED: match pattern & delete matched lines not4google Shell Programming and Scripting 7 11-22-2006 06:58 AM
How to delete lines do NOT match a pattern JumboGeng UNIX for Dummies Questions & Answers 1 09-20-2006 02:52 AM
return previous line for pattern match braindrain UNIX for Dummies Questions & Answers 3 06-26-2006 08:33 AM
match a pattern, print it and the next line nymus7 Shell Programming and Scripting 4 07-28-2005 09:59 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 01-24-2008
Registered User
 

Join Date: Jan 2008
Posts: 7
Concatenating multiple lines to one line if match pattern

Hi all,

I've been working on a script which I have hit a road block now. I have written a script using sed to extract the below data and pumped into another file:

Severity............: MAJORWARNING
Summary:
System temperature is out of normal range.
Severity............: MAJORWARNING
Summary:
Adapter at hardware path 0/4/1/0 : Received an interrupt indicating and
Elastic Store Error Storm
Severity............: MAJORWARNING
Summary:
Adapter at hardware path 0/3/1/0 : Received an interrupt indicating and
Elastic Store Error Storm
Severity............: MAJORWARNING
Summary:
System temperature is out of normal range.

I want to format it to look like this:
"Severity:.......... Summary:........"
"Severity:.......... Summary:........"
"Severity:.......... Summary:........"
"Severity:.......... Summary:........"

so that each ocurance will be in one line

Any ideas? Hope someone can help me quickly.

Thanks
phixsius.
Reply With Quote
Forum Sponsor
  #2  
Old 01-24-2008
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Milano, Italia/Варна, България
Posts: 1,933
With GNU Awk:

Code:
awk 'NF&&$1=RS$1'  RS="Severity" filename
Reply With Quote
  #3  
Old 01-24-2008
Registered User
 

Join Date: Jan 2008
Posts: 7
Hi radoulov,

I ran the line, however this was the output:

Severityeverity............: MAJORWARNING
Severityummary: Adapter at hardware path 0/3/1/0 : Received an interrupt indicating and Elastic
Severitytore Error
Severitytorm
Severityeverity............: MAJORWARNING
Severityummary: Adapter at hardware path 0/4/1/0 : Received an interrupt indicating and Elastic
Severitytore Error
Severitytorm
Severityeverity............: MAJORWARNING
Severityummary:
Severityystem temperature is out of normal range.
Reply With Quote
  #4  
Old 01-24-2008
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Milano, Italia/Варна, България
Posts: 1,933
I said GNU Awk ...
Reply With Quote
  #5  
Old 01-24-2008
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Milano, Italia/Варна, България
Posts: 1,933
Given your sample this should work with non-Gnu Awk:

Code:
awk 'ORS=/:/?FS:RS' filename
Use nawk or /usr/xpg4/bin/awk on Solaris.
Reply With Quote
  #6  
Old 01-24-2008
Registered User
 

Join Date: Jan 2008
Posts: 7
Hey mate,

Thanks alot for your suggestions. Unfort, i'm sorry, its still doesnt produce the result I'm looking...

Think there are any other logics to achieving this?
Reply With Quote
  #7  
Old 01-24-2008
Tytalus's Avatar
Registered User
 

Join Date: Jun 2003
Location: Scotland
Posts: 290
Code:
sed -n '
:a
/Sev/ {
N
/Sev.*Sev/ !{
s/\n/ /
ta
}
P
D
}' infile
is probably close :-)
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:36 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0