Concatenate lines in a single paragraph

Hi all,

May you help me with this?

After extract only some lines that I need from a file, I would like to concatenate the remaining lines in a single line (paragraph).

Source file pattern:

Event Type: Warning
Event Source: Sorting
Event Category: None
Event ID: 1188
Date:  9/10/2008
Time:  9:46:50 PM
User:  Adminis\P1
Computer: MyComp-KKL
Description:
User profile MyComp-KKL(S-1-5-21-3230802392-3390281410-1560515013-1307). 

After extracting text of my interest I get:

Warning
9/10/2008
9:46:50 PM
User profile MyComp-KKL(S-1-5-21-3230802392-3390281410-1560515013-1307). 

But I�m cannot follow with the next step, I would like the next result.
(Join lines like a continuous line)

In date 9/10/2008, 9:46:50 PM. This is a warning from User profile MyComp-KKL(S-1-5-21-3230802392-3390281410-1560515013-1307).

Any help would be very appreciated.

Best regards

hi, if you mean line break then try this:

cat youfile.txt | paste -s -d',' | sed s'/,/, /g'

otherwise if you have allready createed a script then please post it!

if you have Python

d={}
for line in open("file"):
    line=line.strip().split(":")
    d[line[0].strip()]=line[-1].strip()
for k in d.keys():    
    if "User profile" in k: 
        user=k
        break    
print "In date %s, %s. This is a warning from %s." %(d['Date'],d['Time'],user)

output

# ./test.py
In date 9/10/2008, 50 PM. This is a warning from User profile MyComp-KKL(S-1-5-21-3230802392-3390281410-1560515013-1307)..

Alternatively, if you have perl then:

$
$ cat input.txt
Event Type: Warning
Event Source: Sorting
Event Category: None
Event ID: 1188
Date:  9/10/2008
Time:  9:46:50 PM
User:  Adminis\P1
Computer: MyComp-KKL
Description:
User profile MyComp-KKL(S-1-5-21-3230802392-3390281410-1560515013-1307).
$
$ perl -ne '{if (/^(.*):[ ]+(.*)$/) {$x{$1}=$2}
>            elsif (/^User profile/){$p=$_}
> } END {print "In date $x{Date}, $x{Time}. This is a warning from $p"}' input.txt
In date 9/10/2008, 9:46:50 PM. This is a warning from User profile MyComp-KKL(S-1-5-21-3230802392-3390281410-1560515013-1307).
$
$

tyler_durden

Hey guys,

Really thanks to all for your help, for your different solutions to my question; this part of code would help me a lot to continue in my script.

:b: