Formatting the output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Formatting the output
# 1  
Old 02-12-2002
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:
Code:
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 ...
Code:
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...
Code:
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.
# 2  
Old 02-13-2002
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!
# 3  
Old 02-13-2002
Quote:
Assuming that you are reading from a file...
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.
Code:
      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.
# 4  
Old 02-14-2002
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.
# 5  
Old 02-14-2002
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`?
# 6  
Old 02-14-2002
Perderabo,
The IFS="" did the trick and the output is exactly how it was originally intended.
Thanks again.
# 7  
Old 02-15-2002
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?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Formatting the Output

Hi, I am trying to use printf command and format certain output in a specific format as under: While the left side (upto |) of the above format is part of a fixed header function, the right side is where i am expecting data to be printed. However, as seen, Row1 value is reflecting on last... (5 Replies)
Discussion started by: EmbedUX
5 Replies

2. AIX

Help Formatting Output

I am using FORTRAN 90 on AIX 5.3 and need to output my data to a tab-delimited file. It must have actual tabs, and I cannot figure out a way to make it work. The resulting file will be imported into another application (quickbooks) as an .iif file....for some reason, it needs the tabs; spaces do... (2 Replies)
Discussion started by: KathyB148
2 Replies

3. Shell Programming and Scripting

Formatting the output

Hi, I have a file which contents entries in this form. Only in /data4/temp abc.000001 Only in /data4/temp abc.000003 Only in /data4/temp abc.000012 Only in /data4/temp abc.000120 Only in /data4/temp abc.000133 Only in /data4/temp abc.001444 i want to read line by line and format... (2 Replies)
Discussion started by: arijitsaha
2 Replies

4. Shell Programming and Scripting

Output Formatting

Hi Guys I need help removing some lines from output i am receiving from a shell script. Here is the output: http://i52.tinypic.com/10z0fut.png I am trying to remove the output that i have circled. . ${EDW}/extracts/bin/extracts_setup2.sh . ${EDW}/extracts/extracts.conf ... (7 Replies)
Discussion started by: mooey1232003
7 Replies

5. Shell Programming and Scripting

Formatting of output

Hi Experts, I have to create a report for certain audit and my output looks as follows I m trying to format my output to look like Any inputs would be highly appreciated Thanks Syed (5 Replies)
Discussion started by: maverick_here
5 Replies

6. Shell Programming and Scripting

formatting output

Sorry for being a n00b, but I'm having a lot more trouble than I should with formatting the output to the program I finally completed. I'm basically looking for the linux equivalent to setw( ) from c++ so that I can print things in columns like this (but without the underlines lol): MISSPELLED: ... (4 Replies)
Discussion started by: aikaterinimak
4 Replies

7. Shell Programming and Scripting

Formatting ls output

I am using find and ls to search for "warez" files on my server. find /home/ -regex ".*\.\(avi\|mp3\|mpeg\|mpg\|iso\)" -print0 | xargs -0 ls -oh This command produces this: -rw-r--r-- 1 1000 3.2M Feb 18 2009 /home/user/public_html/lupus.mp3 I want to only get this 3.2M... (4 Replies)
Discussion started by: bonrad
4 Replies

8. Shell Programming and Scripting

more help with formatting ls output...

Ok, for a fun project, my goal is to replicate the style of "catalog" on an old apple ] *A 002 SOMEAPPLESOFTFILE B 004 SOMEFILE T 006 SOMETEXT I 002 SOMEINTEGERFILE The first character is either " " or "*" depending on if the file is locked or not. Next is the filetype, so in... (1 Reply)
Discussion started by: patrick99e99
1 Replies

9. Shell Programming and Scripting

Formatting Output

Hi I tried running the below awk 'BEGIN { printf ("%s %-51s %s %-7s %s",$var1,$var2,$var3,$var4,$var5)}' from the command prompt and it is not working. Getting the error awk: Field $() is not correct. The source line number is 1. Actually my requirement is to form a string based on... (6 Replies)
Discussion started by: dhanamurthy
6 Replies

10. Shell Programming and Scripting

formatting output

Hi need some advice.. #grep -i hostname test.csv (gives the below output) HOSTNAME,name,host_test,,,,,,,, Now I need to format the above output as below. HOSTNAME: name=host_test Any easy way of doing this using awk or sed or printf? (4 Replies)
Discussion started by: balaji_prk
4 Replies
Login or Register to Ask a Question