Scripting columns

I've got the following data in a file - basically hundred of passes.

     Pass Id                   : PASSID1
     Pass Name              : 7 day pass 10 Gb
     Pass Group              : uk
     Short Name             : pmbbrh2
     type                       : restrict
     Validity                    : 168 hours
     Pass Id                     : BBFFF009
     Pass Name                : World pass 24hr
     Pass Group               : World
     Short Name               : CsRHhh3
     type                        : block
     Validity                    : 24 hours

What id like is something like the following.

Pass Id    Pass Name       Pass Group   Short Name     type    Validity
PASSID1  7 day pass 1 Gb   uk         pmbbrh2        restrict   168 hours
BBFFF009 World pass 24hr   EU        CsRHhh3        block     24 hours

I know this is something simple, but it actually hurts my mind trying to solve it. I cant use grep or awk or sed for this. any other ideas ?

The data in the first column is the same throughout the file but the data in the second column is sometimes the same.

Thanks in advanced

Jeffers

just wondering the reasons behind such restrictions?

Certain passes can only use certain protocols. if the use protocols that use p2p or skype they are restricted

thanks

I think vgersh99 meant why the restrictions prohibiting the use of grep, sed, and awk.

maybe its my understanding of these commands.

I've tried using awk and grep with the cut command and using ":" as the delimitar but after that i get lost.

some of the values have more than 4 or 5 words and so becomes a complete mess.

Perhaps this will do:

$ awk -F'^ +| *: *' 'function pr(a) {printf("%-10s %-20s %-12s %-12s %-10s %-10s\n", a[1],a[2],a[3],a[4],a[5],a[0])}
{i=NR%6; k=$2; v=$3} NR==6 {pr(k)} !i{pr(v)}' data

Pass Id    Pass Name            Pass Group   Short Name   type       Validity  
PASSID1    7 day pass 10 Gb     uk           pmbbrh2      restrict   168 hours 
BBFFF009   World pass 24hr      World        CsRHhh3      block      24 hours  
PASSID1    7 day pass 10 Gb     uk           pmbbrh2      restrict   168 hours 
BBFFF009   World pass 24hr      World        CsRHhh3      block      24 hours  
PASSID1    7 day pass 10 Gb     uk           pmbbrh2      restrict   168 hours 
BBFFF009   World pass 24hr      World        CsRHhh3      block      24 hours

Cheers,
Alister

Assuming the order of columns is persistent between 'Pass Id'-s and there're no missing columns.

nawk -f jeff.awk myFile

jeff.awk:

BEGIN {
  FS=" *: *"
  tab=sprintf("\t")

  width=20
}

function trim(str)
{
    sub("^([ ]*|" tab "*)", "", str);
    sub("([ ]*|" tab "*)" "$", "", str);
    return str;
}

{ $1=trim($1) }
!($1 in header){ header[$1]; headerL=(headerL)?headerL OFS sprintf("%-*s", width,$1): sprintf("%-*s", width,$1) }
$1 ~ /^ *Pass Id/ {pass=trim($2)}
{ v[pass]=(v[pass])? v[pass] OFS sprintf("%-*s", width,trim($2)) : sprintf("%-*s", width,trim($2)) }
END {
  print headerL
  for(i in v)
     print v
}

Holy S*!t

Dam that looks complicated, i cant even begin to understand that, just when you think you're getting somewhere !!!!!

Thanks i'll give them both a try and get back to you.

thanks again

Jeffers