variable fixed-width fields

Hi there,

CTL  Port        IO Rate(IOPS)      Read Rate(IOPS)     Write Rate(IOPS) Read Hit(%) Write Hit(%)    Trans. Rate(MB/S) Read Trans. Rate(MB/S) Write Trans. Rate(MB/S)   09:36:48
  0     A                  136                    0                  135          97          100                    7                      0                       7   09:36:48
  0     B                    3                    0                    2         100          100                    0                      0                       0   09:36:48
  0     C                   88                   84                    3          35          100                    9                      9                       0   09:36:48
  0     D                  391                  240                  151          44          100                   11                      6                       4   09:36:48
  0     E                    0                    0                    0           0            0                    0                      0                       0   09:36:48

shows the following result:
21
11
11
...

but I need to correlate header fields with rest of table and substitute fixed-width field separator with something else, for instance "\t".

Please advise.

The second task is to merge some columns into the one:
0 A to 0A
0 B to 0B
and so on.

Try:

perl -pe 's/ {2,}/\t/g;s/\) +/\)\t/g;s/^\t//' inputfile
1 Like

Thanx a lot, but I forgot to mention that the "inputfile" is a result of my previous parsing other files in which I use 'awk' and 'csplit' and for further parsing I plan to use the same tools plus 'sort', 'sed'...
Perl is too much :wink:

There you go:

awk '{gsub("  +","\t");gsub("\\) +",")\t");sub("^\t","")}1' inputfile
1 Like

regular expressions! of course!
where was mind? :wink:

going to manual page to learn what "1" after breket does mean

---------- Post updated 22-11-11 at 12:02 AM ---------- Previous update was 21-11-11 at 11:44 PM ----------

'1' means {print}

Indeed.

Okay. About my second task (fields merging). If number of fields is known value then it's easy:

 awk  'BEGIN {FS="\t"; OFS="\t"} {print $1$2, $3, $4, $5, $6, $7, $8, $9, $10 }'

what is the solution when number of fields is unknown?

---------- Post updated at 12:57 PM ---------- Previous update was at 12:45 PM ----------

the answer:

awk  'BEGIN {FS="\t"; OFS="\t"} { $1=$1$2; $2=""; print}' inputfile