![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
With GNU Awk:
Code:
awk 'NF&&$1=RS$1' RS="Severity" filename |
|
#3
|
|||
|
|||
|
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
|
||||
|
||||
|
I said GNU Awk ...
|
|
#5
|
||||
|
||||
|
Given your sample this should work with non-Gnu Awk:
Code:
awk 'ORS=/:/?FS:RS' filename |
|
#6
|
|||
|
|||
|
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
|
||||
|
||||
|
Code:
sed -n '
:a
/Sev/ {
N
/Sev.*Sev/ !{
s/\n/ /
ta
}
P
D
}' infile
|
||||
| Google The UNIX and Linux Forums |