Manipulating a header file using awk or sed

Hi Guys,

Is there a simple way of doing the below.

Available<spaces>Assigned<spaces>Maximum<spaces>Maximum<spaces>Page<spaces>Total <spaces>Used<spaces>Pct<spaces>Max. Pct<CR>
Space<spaces>Capacity<spaces>Extension<spaces>Reduction<spaces>Size<spaces> Usable<spaces>Pages<spaces>Util<spaces>Pct<CR>
(MB)<spaces>(MB)<spaces>(MB)<spaces>(MB)<spaces>(bytes)<spaces>Pages<spaces>Util<CR>

Available Space (MB)#Assigned Capacity (MB)#Maximum Extension (MB)#Maximum Reduction (MB)#Page Size (bytes)#Total Usable Pages#Used Pages#Pct Util#Max. Pct Util

I know that this is quite a complex requirement, any help will be of great assistance, has I have tried but not got anywhere with it.

Thanks.

Ok, what exactly do you want to do? What kind of transformation should be done? What have you tried so far? Because from the text above one can only deduct that you've got a possibly complex requirement, but not what that is.

Ok what I am trying to achieve is that the program would read the first 3 lines and then align the first columns of the first 3 lines together, and the same for the 2nd columns and so forth.

So something like this

Available Assigned
Space Space
(MB) (MB)

would be

Available Space (MB)#Assigned Space (MB)# etc.....

Hope this helps.

Hi, eo29:

$ cat data
Available Assigned Maximum
Space Space Warp
(MB) (MB) (Factor)

$ awk '{for (i=1; i<=NF; i++) a=a (a?" ":"") $i} END {while (a[++j]) printf("%s%s", a[j], a[j+1]?"#":"\n")}' data
Available Space (MB)#Assigned Space (MB)#Maximum Warp (Factor)

Regards,
Alister

A Perl solution:

$ 
$ cat -n f1
     1  Available  Assigned  Maximum  Maximum  Page  Total   Used  Pct  Max. Pct
     2  Space  Capacity  Extension  Reduction  Size   Usable  Pages  Util  Pct
     3  (MB)  (MB)  (MB)  (MB)  (bytes)  Pages  Util
$ 
$ perl -ne 'chomp; if ($.==1){@x1=split/  /} elsif($.==2){@x2=split/  /} else{@x3=split/  /}
             END {foreach $i(0..$#x1){print "$x1[$i] $x2[$i] $x3[$i]#"}}' f1
Available Space (MB)#Assigned Capacity (MB)#Maximum Extension (MB)#Maximum Reduction (MB)#Page Size (bytes)#Total  Usable Pages# Used Pages Util#Pct Util #Max. Pct Pct #$ 
$ 

tyler_durden

Thanks guys, that is brilliant, but somethings the headers dont always match up, like the below

Available Assigned Used Max. Pct Total
Space Space pages Pct Util Sum
(MB) (MB) Util Pages

to

Available Space (MB)#Assigned Space (MB)#Used Pages#Max. Pct Util#Pct Util#Total Sum Pages

If there's no way to key on when a term consumes two words on a line or when it doesn't consume any, you will have to do it manually. If there is a list of special cases, they can be hardcoded.

In the future, please try to remember to consider any special cases when you ask for help. The devil is always in the details.

Regards,
Alister

Well, that is something that you, as a human being, know. The computer doesn't know that. It will simply run the commands that you feed it. So if you tell it to line up the 3rd column from each row, it will do *just* that, and spew back "Used pages Util".
While speed and repetition are its virtues, intelligence isn't (not yet at least.) :wink:

Yet another idea, besides alister's, is to modify the program that generates the file so that there are two spaces between the second "(MB)" and "Util". And consider exactly one space as the delimiter. That way, the 3rd token in the 3rd row would be null. Ditto for the 5th token.

HTH,
tyler_durden

thks guys for your help on this, much appreciated. Now I'm going to drown my sorrows in a vodka of awk, and see what I can do with the above.