#!/bin/csh -f
#
# bfix - fix the output of bextract and sumpat
#  sorts the individual process patterns by first block number
#   useful for seg and lps patterns
#   might work for lpr too
# input from stdin
# output to stdout

# we watch for blank lines (NF==0). This clears inpat, which is
# initially clear. On full lines, we check the flag. If set, remember
# this value. On all full lines, print the remembered value, and the
# rest of the line. Sort by the first thing on each line, the
# "remembered" value. Note blank lines are not output.

awk '\
NF > 0 { \
    if (inpat == 0) {\
    	   inpat = 1;\
    	   start=$1;\
    }\
    print start, $0;\
    next;\
}\
NF == 0 { inpat = 0; }' | sort -0n+1
