The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
return previous line for pattern match braindrain UNIX for Dummies Questions & Answers 4 12-08-2008 05:17 PM
sed - Replace Line which contains the Pattern match with a new line kousikan Shell Programming and Scripting 2 03-24-2007 07:24 AM
SED: match pattern & delete matched lines not4google Shell Programming and Scripting 7 11-22-2006 09:58 AM
How to delete lines do NOT match a pattern JumboGeng UNIX for Dummies Questions & Answers 1 09-20-2006 05:52 AM
match a pattern, print it and the next line nymus7 Shell Programming and Scripting 4 07-29-2005 12:59 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-24-2008
phixsius phixsius is offline
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.
  #2 (permalink)  
Old 01-24-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

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

Code:
awk 'NF&&$1=RS$1'  RS="Severity" filename
  #3 (permalink)  
Old 01-24-2008
phixsius phixsius is offline
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.
  #4 (permalink)  
Old 01-24-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
I said GNU Awk ...
  #5 (permalink)  
Old 01-24-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
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.
  #6 (permalink)  
Old 01-24-2008
phixsius phixsius is offline
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?
  #7 (permalink)  
Old 01-24-2008
Tytalus's Avatar
Tytalus Tytalus is offline Forum Advisor  
echo {1..9}^2\;|bc
  
 

Join Date: Jun 2003
Location: Scotland
Posts: 431
Code:
sed -n '
:a
/Sev/ {
N
/Sev.*Sev/ !{
s/\n/ /
ta
}
P
D
}' infile
is probably close :-)
Sponsored Links
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 10:45 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