Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Merge several lines into one line

Status
Not open for further replies.

trobiani

Technical User
Jan 29, 2008
3
ES
Hi to all,
I am trying to put several lines into one line, this is the source file:
object-group network s_1.1.1.1
description R234575095
network-object host 1.1.1.1
object-group network s_2.2.2.2
network-object host 2.2.2.2
object-group network s_3.3.3.3
description R234560498
network-object host 3.3.3.3

And this this the output that I want:
object-group network s_1.1.1.1 network-object host 1.1.1.1
description R234575095 (this is one line)
object-group network s_2.2.2.2 network-object host 2.2.2.2

The problem is that in several object we don´t have the line "description xxxxx" and for this I have the data in 2 or 3 lines.
Best regards.
Trobiani.
 
A starting point:
awk '/^object/{o=$0;d=""}/desc/{d=$0}/network-obj/{print o""$0;if(d)print d}' input > output

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi PHV,
I need to put the line "description" in the same line, bellow you see the output of your command:
object-group network s_172.24.10.70 network-object host 172.24.10.70 --> 1 line
description R708708 --> 2 line
object-group network s_172.24.10.71 network-object host 172.24.10.71 --> 1 line OK

Thanks for your answer,
Trobiani.
 
Reread your post (And this this the output that I want:) and explain me where I'm wrong.
 
Hi PHV,
You are correct, but in my first post I put the output in two lines because the window for put the messages cut the whole line into 2 lines
Original line:
object-group network s_1.1.1.1 network-object host 1.1.1.1
description R234575095 (this is one line)

Thanks for your help and sorry for my mistake.
Trobiani.
 
You wanted this ?
awk '/^object/{o=$0;d=""}/desc/{d=$0}/network-obj/{print o""$0""d}' input > output

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top