Formatting the output

Hi all,

Have the following code(1) producing the results(2 & 3).
Would like to know if there is a way to format the two reports created in a similar fashion.
IE - The first is formatted nicely as a result of the echo "$xmpbdate $xavgs" >> $xmpbrpt
However when I attempt to do the same on the second report, I don't get the desired formatted result.

The Create_Report Function:

function Create_Report {

  ## Set Std Report File Name.
  xmpbrpt=$xrptdir$2
  ##
  ## Create Header.
  echo "SYSTEM: "`hostname`" (EVEREST-AU)" > $xmpbrpt
  echo "MPSAR(-b) Report (Daily Averages) - "$3", "`echo $2 | cut -c4-7`"."\
        >> $xmpbrpt
  echo "--------------------------------------------------------" >> $xmpbrpt
  echo "- Fields: Date, bread/s, lread/s, %rcache, bwrit/s," >> $xmpbrpt
  echo "-         lwrit/s, %wcache, pread/s, pwrit/s" >> $xmpbrpt
  echo "--------------------------------------------------------" >> $xmpbrpt
  for xmpbfile in $1$2/mpb??
    do
      #-- Get Date of SAR report -----------------------------#
      xmpbmm=`awk '/SCO_SV/' $xmpbfile | cut -c33-34`
      xmpbdd=`awk '/SCO_SV/' $xmpbfile | cut -c36-37`
      xmpbyy=`awk '/SCO_SV/' $xmpbfile | cut -c39-42`
      xmpbdate="$xmpbdd/$xmpbmm/$xmpbyy"
      #-- Get Average Values For The Day ---------------------#
      xavgs=`awk '/Average/' $xmpbfile | sed s/Average//`
      #-- Write details to report ----------------------------#
      echo $xmpbdate $xavgs >> $xmpbrpt
    done  ## End-of (for xmpbfile in $1$2/mpb??)
  echo "--------------------------------------------------------" \
        >> $xmpbrpt
  echo "End-of-Report." >> $xmpbrpt
  echo  >> $xmpbrpt
  #-- Secure Report to operator:group --------------------#
  chown operator:group $xmpbrpt
  chmod 644 $xmpbrpt
  #-- Send Email of Std Report ---------------------------#
  SendEmail $xmpbrpt $4 $3 `echo $2 | cut -c4-7`

  ## Set Detail Report File Name.
  xmpbrpt2=$xrptdir$2.detail
  echo "SYSTEM: "`hostname`" (EVEREST-AU)" > $xmpbrpt2
  echo "MPSAR(-b) Report (Detail) - "$3", "`echo $2 | cut -c4-7`"."\
        >> $xmpbrpt2
  echo "--------------------------------------------------------" >> $xmpbrpt2
  echo "- Fields: Date, time, bread/s, lread/s, %rcache, bwrit/s," >> $xmpbrpt2
  echo "-         lwrit/s, %wcache, pread/s, pwrit/s" >> $xmpbrpt2
  echo "--------------------------------------------------------" >> $xmpbrpt2
  for xmpbfile in $1$2/mpb??
    do
      #-- Get Date of SAR report -----------------------------#
      xmpbmm=`awk '/SCO_SV/' $xmpbfile | cut -c33-34`
      xmpbdd=`awk '/SCO_SV/' $xmpbfile | cut -c36-37`
      xmpbyy=`awk '/SCO_SV/' $xmpbfile | cut -c39-42`
      xmpbdate="$xmpbdd/$xmpbmm/$xmpbyy"
      #-- Get Detail Values for each Day ---------------------#
      #-- Write details to report ----------------------------#
      grep ":" $xmpbfile | grep -v "/" > $xmpbfile.temp
      while read xdetail; do
        echo "$xmpbdate $xdetail" >> $xmpbrpt2
      done < $xmpbfile.temp
      rm $xmpbfile.temp
    done  ## End-of (for xmpbfile in $1$2/mpb??)
  echo "--------------------------------------------------------" >> $xmpbrpt2
  echo "End-of-Report." >> $xmpbrpt
  #-- Secure Report to operator:group --------------------#
  chown operator:group $xmpbrpt2
  chmod 644 $xmpbrpt2

}  ## End-of-function Create_Report

The first report ...

TVL-AU: more Feb2002
SYSTEM: www3.???.???.?? (EVEREST-AU)
MPSAR(-b) Report (Daily Averages) - February, 2002.
--------------------------------------------------------
- Fields: Date, bread/s, lread/s, %rcache, bwrit/s,
-         lwrit/s, %wcache, pread/s, pwrit/s
--------------------------------------------------------
01/02/2002      1054   25865      96      62    1034      94       0       0
02/02/2002       870   44753      98     121     910      87       0       0
03/02/2002       743   45874      98      41     795      95       0       0
04/02/2002       998   26118      96      60     997      94       0       0
05/02/2002       952   27444      97      66    1021      94       0       0
06/02/2002      1185   26738      96      62    1014      94       0       0
07/02/2002      1020   49439      98      55     875      94       0       0
08/02/2002      1088   63444      98      57    1126      95       0       0
09/02/2002       292   14215      98     262     722      64       0       0
10/02/2002      1256   47739      97      42     846      95       0       0
11/02/2002      1209   30135      96      77    1154      93       0       0
12/02/2002      1459   30633      95      73    1149      94       0       0
--------------------------------------------------------
End-of-Report.                                         

And a portion of the second report...

TVL-AU: more Feb2002.detail
SYSTEM: www3.???.???.?? (EVEREST-AU)
MPSAR(-b) Report (Detail) - February, 2002.
--------------------------------------------------------
- Fields: Date, time, bread/s, lread/s, %rcache, bwrit/s,
-         lwrit/s, %wcache, pread/s, pwrit/s
--------------------------------------------------------
01/02/2002 00:15:00 830 27654 97 170 3237 95 0 0
01/02/2002 00:30:00 39 10254 100 22 199 89 0 0
01/02/2002 00:45:00 28 9464 100 20 141 86 0 0
01/02/2002 01:00:00 27 8875 100 13 115 89 0 0
01/02/2002 01:15:00 499 67004 99 57 10206 99 0 0
01/02/2002 01:30:00 356 72201 100 119 7384 98 0 0        

Any help greatfully appreciated.

Assuming that you are reading from a file, or whatever, ensure that the input format of your file is as expected. Maybe put some debug statements as well.

Best Wishes!

Nah, never thought of ever doing that .... re-read the script.

After the grep, the format of the File has a similar structure of the first report, with the exception of a time stamp for each record between the date(1st field) and second field.

      grep ":" $xmpbfile | grep -v "/" > $xmpbfile.temp
      while read xdetail; do
        echo "$xmpbdate $xdetail" >> $xmpbrpt2
      done < $xmpbfile.temp
      rm $xmpbfile.temp

I'm suspecting that the read is the cause, but know not how to overcome this.

What shell are you using? I notice that you rm $xmpbfile.temp immediately after using it. Have you tried commenting that out so you can look at the file? Have you tried an "echo $xdetail" immediately after the read so you can see id xdetail is screwed up at that point?

If you are using ksh and the file really does look good, and xdetail is bad after the read, I would have to say that ksh has a bug. If the read statement is acting up, a
IFS=""
before the loop with the read may fix it.

Perderabo,
Firstly thanks for the responce.

I'm using `bash` as the running shell, we do have `ksh` but we happen to write most of our scripts in `bash` so `ksh` doesn't ever get much of a look in.

I have done some debugging (whilst not shown); performing a `cat` on the .temp file immediately after the `grep` statements and the output is formatted correctly. But after the read, the record being read is shrunk and similar to the second output example.

I hadn't mentioned it before, but the input file is the result of a `mpsar -b`(SCO Unix) - just to provide some indication of what I'm playing with. (I create a daily file every night)

I'll try the IFS="" and see if that makes any difference.

BTW - Is there any advantages in using `ksh` over `bash`?

Perderabo,
The IFS="" did the trick and the output is exactly how it was originally intended.
Thanks again.

I'm glad you got your problem solved, but it still liiks like bash has a bug. I tried a few experiments with bash and I can't get the read to behave like that. I've seen bash fail before on complex scripts. This is a partial answer to your question: "Is there any advantages in using `ksh` over `bash`?" Also bash does not support coroutines nor does it support self-formating variables.

Bash's lack of formating nailed you in this thread. You must find that bash offers something in compensation since you haven't switched to ksh. So, why do you like bash?

Perderabo,
I'm going to forward what you've mentioned to my Sys Admin. he'll be very interested to read what you've written - thank-you.

To your question "So, why do you like bash?", well quite simply, it's all I've ever used. It's been the default sh on every system that I've sat on.

I've installed Mandrake 8.0 on my PC (dual boot) at home but haven't yet had much time to play with it.

Again, thanks for all your assistance with this problem.