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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

host and package on one line 1

Status
Not open for further replies.
Apr 8, 2014
13
US
Code:
host1
cups-libs-1.4.2-67.el6.x86_64
cups-1.4.2-67.el6.x86_64
host2
cups-libs-1.4.2-67.el6.x86_64
cups-1.4.2-67.el6.x86_64
host3
cups-1.4.2-67.el6.x86_64
host4
cups-libs-1.4.2-67.el6.x86_64
host5
cups-libs-1.4.2-67.el6.x86_64
host6
cups-libs-1.4.2-67.el6.x86_64
cups-1.4.2-67.el6.x86_64
Desired output
Code:
host1 cups-libs-1.4.2-67.el6.x86_64 cups-1.4.2-67.el6.x86_64
host2 cups-libs-1.4.2-67.el6.x86_64 cups-1.4.2-67.el6.x86_64
host3 cups-1.4.2-67.el6.x86_64
host4 cups-libs-1.4.2-67.el6.x86_64
host5 cups-libs-1.4.2-67.el6.x86_64
host6 cups-libs-1.4.2-67.el6.x86_64 cups-1.4.2-67.el6.x86_64
Tried this but it isn't working as I thought.
Code:
awk '{
  if(/^host/)
    {host=$0}
  else if (/^cups/)
    {pkg[$0]++}
  {for (i in pkg) print host" "i}
}' $1
 
Hi

If one host's cups are always occur consecutively, I prefer to not stack up the data, just to delay it :
Code:
awk 'p[teal]{[/teal][b]printf[/b][i][green]"%s%s"[/green][/i][teal],[/teal]p[teal],[/teal][fuchsia]/^host/[/fuchsia][teal]?[/teal]ORS[teal]:[/teal]OFS[teal]}{[/teal]p[teal]=[/teal][navy]$0[/navy][teal]}[/teal][b]END[/b][teal]{[/teal][b]print[/b] p[teal]}[/teal]' $1


Feherke.
feherke.ga
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top