Help with a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help with a script
# 1  
Old 03-04-2016
Help with a script

Gents,

Could you please modify this script.. using the files attached I want to create a histogram.

It was working in a old machine.. ( unix ).

Now i am using debian and it does not work. can please help.

Is there the possibility to transform it to bash

Here the script

Code:
#!/bin/awk -f
#           Awk program file.
# Name    : histo.awk
# Purpose : 
# Syntax  : ...| awk -f histo.awk 
#-------------------------------------------------------------------------------
# On range dans nbclasse 
# < min : va dans histogramme[0]
# >= max : va dans histogramme[nbclasse+1]
#
# Getting parameters from header
#
/^H/ {
  
  min = $2
  max = $3
  intervalle = $4

  nbclasse = (max-min)/intervalle

} 

#
# Distributing results
#
$0 !~/^H/ {

   if ( isnotfirst == 0 ) {
      min_ech = $1
      max_ech = $1
   } else {
      if ( min_ech > $1 )
         min_ech = $1
      if (max_ech < $1 )
         max_ech = $1
   }
   isnotfirst = 1 

   value = $1 
   classe = int((value-min)/(max-min)*nbclasse) + 1

   if ( value < min  ) 
      classe  = 0
   if ( value >= max )
      classe = nbclasse+1

   histogramme[classe]++
   mytot++
   if ( value > min && value <= max ) {
      TOTAL += value
      nb_average ++
   } 
      
} 


#
# Drawing graph
#
END {

   # Get number of samples in the most filled class
   for ( i =0 ; i<=nbclasse +1 ; i ++ )
      if (histomax <histogramme[i] )
         histomax = histogramme[i]
  
   printf ( "Class          %%     Nb Bargraph\n" )

   # Print lower than limit occurrences
   printf ( " <= %d      : %2.0f %6d ", min, histogramme[0]/ mytot * 100, 
      histogramme[0] ) 
   bar(histogramme[0], histomax) 

   # To check...
   histot+= histogramme[0]
 
   # Print the distribution
   for ( i = 1; i <= nbclasse;i ++ ) {

      percent = histogramme[i] / mytot * 100;
      sumpercent += percent

      printf ( "[%3d - %3d[ : %2.0f %6d ", min + (i-1) * intervalle, 
         min + i * intervalle, percent,  histogramme[i] )
      bar(histogramme[i],histomax)

      # To check...
      histot+= histogramme[i]

   }

   # Print higher than limit occurrences
   printf ( " >  %d      : %2.0f %6d ", max, 
      histogramme[nbclasse+1]/ mytot * 100, histogramme[nbclasse+1] ) 
   bar(histogramme[nbclasse+1],histomax )

   # To check...
   histot+= histogramme[nbclasse+1]

   printf( "My total           : %d\n", mytot )  
   printf( "Sum of all classes : %d\n", histot )  
   printf( "Sum of percentages : %.3f\n", 
      sumpercent + (histogramme[0]+histogramme[nbclasse+1])/ mytot * 100 )
   printf( "Average (in limits): %.3f\n", TOTAL/nb_average )
   printf( "Minimum            : %.3f\n", min_ech )  
   printf( "Maximum            : %.3f\n", max_ech )  
 

}

function bar ( nb, max ) {

   for ( j = 0.0 ; j < nb; j+= max/50 )
      printf ( "-" )
   printf ( "\n" )

}

# 2  
Old 03-04-2016
The header on the txt file provided does not have any lines that start with H (/^H/) so some parameters are not set and this will cause divide by 0 errors.
This User Gave Thanks to rdrtx1 For This Post:
# 3  
Old 03-05-2016
Thanks rdrtx1,

Yes you right, i forget to say that before execute the script histo.awk.I format the file attached using this code:
Code:
awk 'BEGIN {
           printf ("H 30 75 2\n")
           }
           {
            printf ("%10.2f\n", $7)
           }' patt_length.txt | histo.awk

Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to block first bash script until second bash script script launches web server/site?

I'm new to utilities like socat and netcat and I'm not clear if they will do what I need. I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes. I'm using Cygwin bash on Windows 10. My... (3 Replies)
Discussion started by: siegfried
3 Replies

2. Shell Programming and Scripting

Shell script works fine as a standalone script but not as part of a bigger script

Hello all, I am facing a weird issue while executing a code below - #!/bin/bash cd /wload/baot/home/baotasa0/sandboxes_finance/ext_ukba_bde/pset sh UKBA_publish.sh UKBA 28082015 3 if then echo "Param file conversion for all the areas are completed, please check in your home directory"... (2 Replies)
Discussion started by: ektubbe
2 Replies

3. UNIX for Dummies Questions & Answers

Calling a script from master script to get value from called script

I am trying to call a script(callingscript.sh) from a master script(masterscript.sh) to get string type value from calling script to master script. I have used scripts mentioned below. #masterscript.sh ./callingscript.sh echo $fileExist #callingscript.sh echo "The script is called"... (2 Replies)
Discussion started by: Raj Roy
2 Replies

4. Shell Programming and Scripting

Script will keep checking running status of another script and also restart called script at night

I am using blow script :-- #!/bin/bash FIND=$(ps -elf | grep "snmp_trap.sh" | grep -v grep) #check snmp_trap.sh is running or not if then # echo "process found" exit 0; else echo "process not found" exec /home/Ketan_r /snmp_trap.sh 2>&1 & disown -h ... (1 Reply)
Discussion started by: ketanraut
1 Replies

5. Shell Programming and Scripting

create a shell script that calls another script and and an awk script

Hi guys I have a shell script that executes sql statemets and sends the output to a file.the script takes in parameters executes sql and sends the result to an output file. #!/bin/sh echo " $2 $3 $4 $5 $6 $7 isql -w400 -U$2 -S$5 -P$3 << xxx use $4 go print"**Changes to the table... (0 Replies)
Discussion started by: magikminox
0 Replies
Login or Register to Ask a Question