Operating System - HP-UX
1752675 Members
5866 Online
108789 Solutions
New Discussion юеВ

from horizon text format into vertical text format

 
SOLVED
Go to solution
Matthew_50
Valued Contributor

from horizon text format into vertical text format

set 1,
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
12 0 0 0 0 0 0 18k 0 0 0 0 0 0 0 0


16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
0 22m 0 0 0 0 0 0 0 0 0 0 17k 0 0 0


Total
23m

set 2.
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
1m 0 0 0 0 0 0 800k 0 0 0 0 0 0 0 0


16 17 18 19 20 21 22 23 24 Total
0 0 200k 0 0 0 0 0 0 2m

each set, number of columns will be dynamicly output from other scripts, but will end with "Total" column, for example, how do i convert set 1 into,
0:12
1:0
.
.
.
7:18k
.
.
.
17:22m
.
28:17k
.
Total:23m

and set 2 into

0:1m
.
.
7:800k
.
.
18:200k
.
.
Total:2m


shell script is prefer, thank you.
25 REPLIES 25
James R. Ferguson
Acclaimed Contributor

Re: from horizon text format into vertical text format

Hi:

This appears to meet your needs:

# cat ./reformat#!/usr/bin/awk -f
/^Total/ {print;next;print;next}
/^[ ]*$/ {next}
{
LINE1=$0
n=split(LINE1,a," ")
getline LINE2
m=split(LINE2,b," ")
for (i=1; i}

...

Run as:

# ./reformat file

...where "file" contains a set of data as shown.

Note that in the regular expression:

^[ ]*$/

the whitespace consists of a blank character followed by a TAB character. This skips blank lines in the input.

Regards!

...JRF...

Matthew_50
Valued Contributor

Re: from horizon text format into vertical text format

what if data looks like following ?

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
=============================================
12 0 0 0 0 0 0 18k 0 0 0 0 0 0 0 0


16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
=============================================
0 22m 0 0 0 0 0 0 0 0 0 0 17k 0 0 0

Total
=========
40m

same output. how do i skip "=", must using grep -v "=" ? Thank you.
Steven E. Protter
Exalted Contributor

Re: from horizon text format into vertical text format

Shalom,

grep -v excludes the search parameter.

Only use grep -v for excludes. Use other options for grep to give you equals.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
James R. Ferguson
Acclaimed Contributor
Solution

Re: from horizon text format into vertical text format

Hi (again):

> same output. how do i skip "=", must using grep -v "=" ?

No, 'awk' has all the power of 'grep' and more!

# cat ./reformat
#!/usr/bin/awk -f
/^Total/ {print;next;print;next}
/^[ ]*$/ {next}
{
LINE1=$0
n=split(LINE1,a," ")
getline LINE2
if (LINE2~/======/) {next;getline LINE2}
m=split(LINE2,b," ")
for (i=1; i}

...run as:

# ./reformat file

Regards!

...JRF...


James R. Ferguson
Acclaimed Contributor

Re: from horizon text format into vertical text format

Hi (again):

> SEP: Only use grep -v for excludes

Yes, and that's exactly what he wants to do. My point in _not_ using 'grep' was why have an extra process when 'awk' can do it all?

However, if Matthew wanted to use my original solution he could have done:

# grep -v "======" file | ./reformat

Regards!

...JRF...
Steven E. Protter
Exalted Contributor

Re: from horizon text format into vertical text format

Yea,

JRF reads my mind and interprets what I meant to say. He's da man.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Matthew_50
Valued Contributor

Re: from horizon text format into vertical text format

what is source like this.

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Total
==============================================================================================
slot 9: 144m 0 212m 67m 123 0 789 0 0 0 0 0 0 0 0 0 423m

and reformat into

slot 9/16: 144m
slot 9/17: 0
slot 9/18: 212m
slot 9/19: 67m
.
.
.
slot 9/Total: 423m

possible ? Thanks.
Matthew_50
Valued Contributor

Re: from horizon text format into vertical text format

attach input sample
James R. Ferguson
Acclaimed Contributor

Re: from horizon text format into vertical text format

Hi Matthew:

Given your posted input, you could use the attached Perl script.

Run as:

# ./reformat file

Regards!

...JRF...