Sponsored Content
Full Discussion: Improve script
Top Forums Shell Programming and Scripting Improve script Post 302986317 by jiam912 on Wednesday 23rd of November 2016 12:50:42 PM
Old 11-23-2016
RudiC
Finally I did something to get the desired output it is long but works ...
here the script.
Code:
#!/bin/bash
dd=56
awk -F, -v CATS="-10,-5,0,15,25,35,50" '
NR==1   {CNTLM = split (CATS, LMT)                                      
        }
        {LNC[$6]++                                                      
         for (IX=1; IX<=CNTLM; IX++) if ($10 <= LMT[IX]) break          
         CNT[$6,IX]++                                                   
        }  
END     {printf "FLD6"                                                  
         for (IX=1; IX<=CNTLM; IX++) printf "%6d", LMT[IX]
         printf "" RS                          
           for (l in LNC)                                                 
                {printf "%4d", l                                         
                 for (IX=1; IX<=CNTLM; IX++) printf "%6d", CNT[l,IX] +0
                 printf RS                                         
                }
        }
' test1 > tmp2

awk 'NR>1{print}' tmp2 | sort -k1n > tmp3

#header
awk '
 NR==1{print}' tmp2 > header 
awk     'BEGIN  {DASH=sprintf("%'$dd's",_); gsub(/ /,"-",DASH); print DASH}' >> header 

#sum columns
awk '
 {for (i=2;i<=NF;i++) a[i]+=$i} 
  END{for (i=2;i<=NF;i++) printf"%6s", a[i]}' tmp3 |
  awk '{print "TbyH"$0}' > tmp4 

cat tmp3 tmp4 > tmp5 
awk 'NR>1{for(i=1;i<=NF;i++) t+=$i; print $0 "  =  " t; t=0 }' tmp5 > tmp6

awk     'BEGIN  {DASH=sprintf("%'$dd's",_); gsub(/ /,"-",DASH); print DASH}' >> tmp6

#count columns 

awk '
      {for(i=2;i<=NF;i++) a[i]+=$i>0}
      END{for(i=2;i<=NF;i++)printf"%6s", a[i]}' tmp3 |
  awk '{print "TViU"$0}' | awk 'END{print}' > tmp7 
awk     'BEGIN  {DASH=sprintf("%'$dd's",_); gsub(/ /,"-",DASH); print DASH}' >> tmp7
   
cat  header tmp6 tmp7 > out.txt
sed -i '/TbyH/ i --------------------------------------------------------' out.txt
rm -f *tmp*


the output here:

Code:
FLD6   -10    -5     0    15    25    35    50     TbyV
--------------------------------------------------------
   2     0     0     2  1091   118     9     1  =  1223
   8     0     0     4  1193     3     1     0  =  1209
   9     0     0     2  1180     3     0     0  =  1194
  10     0     0     2   750    24     3     0  =  789
  12     0     0     2   967    31     0     0  =  1012
  13     0     0     3   967     4     0     0  =  987
  14     0     0     0   369     7     1     0  =  391
  15     0     0     4   916    19     0     0  =  954
  18     0     0     2   769     6     1     0  =  796
  22     0     0     2  1034   169    12     0  =  1239
  24     0     0     3  1154    24     0     0  =  1205
  28     0     0     0  1100    48     7     1  =  1184
--------------------------------------------------------
TbyH     0     0    26 11490   456    34     2  =  12008
--------------------------------------------------------
TViU     0     0    10    12    12     7     2
--------------------------------------------------------

please try to short the script to get the desired output.

Thanks a lot.

Last edited by jiam912; 11-23-2016 at 02:13 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Can I improve this script ???

Hi all, Still a newbie and learning as I go ... as you do :) Have created this script to report on disc usage and I've just included the ChkSpace function this morning. It's the first time I've read a file (line-by-bloody-line) and would like to know if I can improve this script ? FYI - I... (11 Replies)
Discussion started by: Cameron
11 Replies

2. Shell Programming and Scripting

Any way to improve performance of this script

I have a data file of 2 gig I need to do all these, but its taking hours, any where i can improve performance, thanks a lot #!/usr/bin/ksh echo TIMESTAMP="$(date +'_%y-%m-%d.%H-%M-%S')" function showHelp { cat << EOF >&2 syntax extreme.sh FILENAME Specify filename to parse EOF... (3 Replies)
Discussion started by: sirababu
3 Replies

3. Shell Programming and Scripting

Improve the performance of a shell script

Hi Friends, I wrote the below shell script to generate a report on alert messages recieved on a day. But i for processing around 4500 lines (alerts) the script is taking aorund 30 minutes to process. Please help me to make it faster and improve the performace of the script. i would be very... (10 Replies)
Discussion started by: apsprabhu
10 Replies

4. Shell Programming and Scripting

Want to improve the performance of script

Hi All, I have written a script as follows which is taking lot of time in executing/searching only 3500 records taken as input from one file in log file of 12 GB Approximately. Working of script is read the csv file as an input having 2 arguments which are transaction_id,mobile_number and search... (6 Replies)
Discussion started by: poweroflinux
6 Replies

5. UNIX for Dummies Questions & Answers

[please] improve my shell/SQL*Plus script

Hi We generate with PL/SQL *.csv files, archive them and mail to the customer. Here is my script (Solaris 10, ksh): #!/bin/ksh # Unix Shell Script Structure for PL/SQL queries with SQL*Plus . ~/.profile scriptdir=/opt/ora/scripts queryname1=example... (1 Reply)
Discussion started by: slashdotweenie
1 Replies

6. Shell Programming and Scripting

Var Check Script (Help improve if possible)

I am working on a script to check the var on all of my systems. Can someone help me fix it to work better or give me suggestions. #!/bin/ksh IN=/path/to/list_of_workstations.txt while read hostnames do if ping $hostnames 1 | grep alive > /dev/null then percent=`ssh -q... (3 Replies)
Discussion started by: whotippedmycow
3 Replies

7. UNIX for Dummies Questions & Answers

How to improve the performance of this script?

Hi , i wrote a script to convert dates to the formate i want .it works fine but the conversion is tkaing lot of time . Can some one help me tweek this script #!/bin/bash file=$1 ofile=$2 cp $file $ofile mydates=$(grep -Po '+/+/+' $ofile) # gets 8/1/13 mydates=$(echo "$mydates" | sort |... (5 Replies)
Discussion started by: vikatakavi
5 Replies

8. Shell Programming and Scripting

Improve sftp script

Dear all, I have written two scripts to transfer files to another server outside the company. One is a batch script , and the other script calls the batch script, send the files and archive the file sent. The problem is, that I want to get the list of files which have been uploaded the the... (10 Replies)
Discussion started by: arrals_vl
10 Replies

9. Shell Programming and Scripting

How to improve an script?

Gents. I have 2 different scripts for the same purpose: raw2csv_1 Script raw2csv_1 finish the process in less that 1 minute raw2csv_2 Script raw2csv_2 finish the process in more that 6 minutes. Can you please check if there is any option to improve the raw2csv_2. To finish the job... (4 Replies)
Discussion started by: jiam912
4 Replies

10. Shell Programming and Scripting

Improve script and get new output file

Gents, Using the following script, I got the changes as desired in the output file called (spread_2611.x01.new). Complete file as input (spread_2611.x01). Can you please have a look to my script and improve it please. :b: Also I would like to I get a additional selecting only the records... (21 Replies)
Discussion started by: jiam912
21 Replies
Graphics::Primitive::Insets(3pm)			User Contributed Perl Documentation			  Graphics::Primitive::Insets(3pm)

NAME
Graphics::Primitive::Insets - Space between things DESCRIPTION
Graphics::Primitive::Insets represents the amount of space that surrounds something. This object can be used to represent either padding or margins (in the CSS sense, one being inside the bounding box, the other being outside) SYNOPSIS
use Graphics::Primitive::Insets; my $insets = Graphics::Primitive::Insets->new({ top => 5, bottom => 5, left => 5, right => 5 }); METHODS
Constructor new Creates a new Graphics::Primitive::Insets. Instance Methods as_array Return these insets as an array in the form of top, right, bottom and left. bottom Set/Get the inset from the bottom. equal_to Determine if these Insets are equal to another. left Set/Get the inset from the left. right Set/Get the inset from the right. top Set/Get the inset from the top. zero Sets all the insets (top, left, bottom, right) to 0. AUTHOR
Cory Watson, "<gphat@cpan.org>" SEE ALSO
perl(1) COPYRIGHT &; LICENSE Copyright 2008-2010 by Cory G Watson. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.12.3 2010-08-21 Graphics::Primitive::Insets(3pm)
All times are GMT -4. The time now is 12:12 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy