I guess that I'm not surprised that code that was written to extract 4 left-justified fields from an input line doesn't correctly extract 6 fields (some left-justified and some right-justified) with completely different field alignments. If you give us sample input that is not representative of your real input, you're wasting all of our time. With your new sample input, the following updated awk script does something that I am guessing is closer to what you want, but (since you didn't show what the output should be), it is just a guess:
awk '
function extract_field(first, last, string) {
string = substr($0, first, last - first + 1)
sub(/^ */, "", string)
sub(/ *$/, "", string)
return string == "" ? "-" : string
}
/^$/ { next
}
/\t/ { # Convert tabs in input to spaces assuming tab stops are set in columns
# 9 + 8x.
while(i = index($0, "\t")) $0 = substr($0, 1, i - 1) \
sprintf("%.*s", 8 - (i - 1) % 8, " ") substr($0, i + 1)
}
{ # At this point, field 1 is characters 1-32, field 2 is characters
# 33-43, field 3 is characters 44-55, and field 4 is characters 56-62,
# field 5 is characters 63-69, and field 6 is characters 70-EOL. All
# of these fields offsets are guesses based on provided sample input.
printf("%s%s\n%s\n%s\n%s\n%s\n%s\n",
oc++ ? "\n" : "",
extract_field(1,32),
extract_field(33,43),
extract_field(44,55),
extract_field(56,62),
extract_field(63,69),
extract_field(70,100))
}' testify.log2
When your new sample input is saved in a file named testify.log2, the above script produces the output:
db file scattered read
2,189,675
4,308
2
52.3
User I/O
DB CPU
-
2,854
-
34.6
-
direct path read
308,043
811
3
9.8
User I/O
PX Nsq: PQ load info query
950
189
199
2.3
Other
db file sequential read
215,085
165
1
2.0
User I/O
control file sequential read
105,321
127
1
8.1
System I/O
Of course, there are no tabs in the sample input you've shown us. And, if there is a tab at the end of each field but the last, your tab stops are not set at multiples of eight character boundaries.
Is that what you want?