"Fossies" - the Fresh Open Source Software Archive

Member "statist-1.4.2/tests/test_xcols.sh" (9 Sep 2006, 2195 Bytes) of package /linux/privat/old/statist-1.4.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/bin/sh
    2 
    3 # Based on test_4_1.sh written by Bernhard Reiter.
    4 
    5 # With this script we will read a fixed width datafile with information about
    6 # people, identify the couples and calculate both the mean age difference and
    7 # the mean income difference between husbands and wives. The entire process was
    8 # made by hand before and the results must coincide.
    9 
   10 # Extracting columns from fixed width datafile
   11 ./run_statist.sh --silent --xcols xcols.config xcols.dat people.dat
   12 
   13 
   14 # Creating key variable for merging the data files later
   15 awk '{if(/state/){print "#%key" "\t" $0} else
   16        {
   17          if(NF == 0) {print $0}
   18          else{
   19           {key = $1$2$3} {print key "\t" $0}
   20          }
   21        }
   22 }' people.dat > people_with_key.dat
   23 
   24 
   25 # Creating the two data files that will be merged
   26 awk '{if(/state/ || NF == 0){print $0} else
   27         {if($5 < 3 && $6 == 0) {print $0}}
   28 }' people_with_key.dat > men.dat
   29 
   30 awk '{if(/state/ || NF == 0){print $0} else
   31         {if($5 < 3 && $6 == 1) {print $0}}
   32 }' people_with_key.dat > women.dat
   33 
   34 
   35 # Merging the two data files
   36 join -e "" women.dat men.dat > couples1.dat
   37 
   38 # Making the file more human readable
   39 sed 's/\ /\t/g
   40 s/#%state/state/g' couples1.dat > couples2.dat
   41 
   42 # Creating variables "Age difference between husband and wife" and "Income
   43 # difference between husband and wife"
   44 awk '{if(/state/){print $0 "\tage_d\tincome_d"} else
   45        {
   46          if(NF == 0) {print $0}
   47          else{
   48           {ad = $14 - $7} {id = $15 - $8} {print $0 "\t" ad "\t" id}
   49          }
   50        }
   51 }' couples2.dat > couples.dat
   52 
   53 
   54 expected="
   55 #Result general statistical information in a table
   56 #n  mean    m-conf  m+conf  median  me_c_lo me_c_up quar_lo quar_up sdv varc(%) sdv_err min max
   57 7   103.286 -56.6998    263.271 100 -111    450 -56 284.5   173.093 167.586728  65.4231 -111    450 "
   58 
   59 
   60 menu="4
   61 1
   62 income_d
   63 
   64 
   65 
   66 0
   67 0
   68 "
   69 actual=`echo "${menu}" | ./run_statist.sh --silent --bernhard couples.dat | sed -e 1d`
   70 
   71     if [ x"${expected}" != x"${actual}" ]; then
   72         echo "Problem with --xcols" ;
   73         echo "Expected:";
   74         echo "${expected}";
   75         echo "Got:";
   76         echo "${actual}";
   77         exit 1;
   78     fi
   79     
   80 rm -f couples*.dat men.dat people.dat people_with_key.dat women.dat
   81 
   82 exit 0
   83