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

put data into colums 3

Status
Not open for further replies.

kHz

MIS
Dec 6, 2004
1,359
US
I have a file that contains:
host1
IP Address: xxx.xx.xxx.xx
Gateway address: xxx.xx.xxx.xx
Netmask: xxx.xxx.xxx.xxx
Ethernet address: 06:04:db:8g:43:4f

host2
IP Address: xxx.xx.xxx.xx
Gateway address: xxx.xx.xxx.xx
Netmask: xxx.xxx.xxx.xxx
Ethernet address: 06:04:ce:8b:ff:ce
.
.
.

What I would like is:
IP Address Gateway Address Netmask Ethernet address
host1 xxx.xx.xxx.xx xxx.xxx.xx.xxx xx.xx.xxx 00:00:00:00
host2 xxx.xx.xxx.xx xxx.xxx.xx.xxx xx.xx.xxx 00:c0:40:30
.
.
.

Thanks!
 
something to start with:
Code:
BEGIN {
  FS=RS=""
  OFS=" "
}

{
  for(i=1; i<=NF; i++)
     printf("%s%s", substr($i,index($i, ":")+1), (i==NF) ? "\n": OFS )
}

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Code:
BEGIN { RS="";  FS=" *\n[^:]*: *"
  pfmt( "", "IP Address", "Gateway Address",
        "Netmask",  "Ethernet address" ) }

{ pfmt( $1, $2, $3, $4, $5 ) }

function pfmt( a,b,c,d,e )
{ printf "%-5s %14s  %15s  %15s  %18s\n",
    a,b,c,d,e
}
 
Code:
/^ +$/ {next}
{
    nf = split($0, a, ": +")
    if (nf == 1) {
        stubs[++r] = a[1]
        c = 0
    } else {
        banners[++c] = a[1]
        data[r, c] = a[2]
    }
}
END {
    printf "%-10s", ""
    for (i=1; i<=c; i++)
        printf "%-20s%s", banners[i], i<c? "": "\n"
    
    for (j = 1; j<=r; j++) {
        printf "%-10s", stubs[j]
        for (k=1; k<=c; k++)
            printf "%-20s%s", data[j,k], k<c? "": "\n"
    }
}
 
Thank you all! I got the output I needed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top