Order text by delimiters

I try order the content from file by delimiters.
This is the text:

interface Loopback0
 description !!!RID RR_SLT
 ip address 172.31.128.19 255.255.255.255

interface GigabitEthernet0
 description !!!P_SLT GI0/0/9
 ip address 172.31.130.246 255.255.255.252

and the result that I need is:

interface Loopback0,description !!!RID RR_SLT, ip address 172.31.128.19 255.255.255.255 (line 1)

interface GigabitEthernet0, description !!!P_SLT GI0/0/9, ip address 172.31.130.246 255.255.255.252 (line2)

Is this possible?

Thanks.

Something like this should do the trick:

awk '{$1=$1}1' FS="\n" RS= OFS="," file
local $/="\n\n";
while(<DATA>){
	s/\n/, /g;
	print $_,"\n";
}
__DATA__
interface Loopback0
 description !!!RID RR_SLT
 ip address 172.31.128.19 255.255.255.255

interface GigabitEthernet0
 description !!!P_SLT GI0/0/9
 ip address 172.31.130.246 255.255.255.252

Works, thanks!...but how redirect the result to file!. Sorry for my english again.

awk '{$1=$1}1' FS="\n" RS= OFS="," file > out

Thanks for all! :b:

perl:

local $/="\n\n";
while(<DATA>){
	s/\n/ /g;
	s/$/"(line ". $. .")"/e;
	print $_,"\n";
}
__DATA__
interface Loopback0
 description !!!RID RR_SLT
 ip address 172.31.128.19 255.255.255.255

interface GigabitEthernet0
 description !!!P_SLT GI0/0/9
 ip address 172.31.130.246 255.255.255.252

With awk is this possible?
I mean...something like this:

When find 'interface' put all lines with de 'interface word in the field $1, and
if find 'description' put all lines in the field $2, and if find 'ip' put all lines in the field $3.

Thanks for tour answers!! :b:

Something like this?

awk '/interface/{s=$0} /description/{s=s FS $0} /ip/{print s FS $0} ' file

thanks, is what I need....but how write de output in a file?

the command awk .......> file_output did not work.

That's exact the same question you've asked above. Please read some books/tutorials regarding shell scripting.

Here you can find the answer to your question:

All about redirection

Regards

Ok Thanks.