can you design/create a script for this?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting can you design/create a script for this?
# 1  
Old 05-20-2009
can you design/create a script for this?

Hello ALL,

I have a file say test.txt, data in that file is in format such that
1st column represents number of executions of particular function
2nd column represents total amount of time
3rd column represents function name

I want to get the poor/slow performing function from this file.
So, ideally what need to do is...
(1) divide the 2nd column by 1st column
(make sure there is no divide by ZERO error)
(2) sort the output in such a way that the record with greater output of step(1) is at top
(3) depending on this sorting display the result file.
result should not contain the division but should contain the original value.

example...

inputfile...

$ cat test.txt
3 (0 sec, 804275 nanosec) abcd
721 (253 sec, 632655866 nanosec) efgh
1873 (21 sec, 887264375 nanosec) hijk
2006 (0 sec, 922300 nanosec) lmhn
3 (0 sec, 3332 nanosec) sjhfdf
2 (0 sec, 2367 nanosec) dkfi
580 (0 sec, 2138703 nanosec) dfhjf
44486 (0 sec, 858447770 nanosec) oet
21102 (739 sec, 891470054 nanosec) lldff
140 (0 sec, 90282 nanosec) sfowe
123 0 sec, 324590 nanosec) xjjv
8939 (0 sec, 337230856 nanosec) asadj
19 (0 sec, 1455434 nanosec) sahjdi
210 (0 sec, 89131 nanosec) posdio
3 (0 sec, 3750149 nanosec) jhd
873 (260 sec, 715043557 nanosec) lppeuv
16 (0 sec, 212024 nanosec) hjass
13668 (2 sec, 506391927 nanosec) nnuua

-------------<end of file>------------------------

here... after division we see these are greater...
253/721 = 0.35090152
260/873 = 0.29782359

so output should look like...
721 (253 sec, 632655866 nanosec) efgh
873 (260 sec, 715043557 nanosec) lppeuv
.
.
likewise...
# 2  
Old 05-20-2009
What have you tried so far

Jean-Pierre.
# 3  
Old 05-20-2009
I dont know how to do division...of
records like... 721 (253 sec, 632655866 nanosec) efgh
plz help me to write the awk or any other script....
# 4  
Old 05-20-2009
try this
Code:
awk -F"[( ]" '{printf "%f %s\n",($3+($5/1000000000))/$1,$NF}' file|sort -r -k1

# 5  
Old 05-20-2009
Code:
while(<DATA>){
	if(/([0-9]+)\s*\(([0-9]+)/){
		print $_ if $2*100/$1 >=20;
	}
}
__DATA__
3 (0 sec, 804275 nanosec) abcd
721 (253 sec, 632655866 nanosec) efgh
1873 (21 sec, 887264375 nanosec) hijk
2006 (0 sec, 922300 nanosec) lmhn
3 (0 sec, 3332 nanosec) sjhfdf
2 (0 sec, 2367 nanosec) dkfi
580 (0 sec, 2138703 nanosec) dfhjf
44486 (0 sec, 858447770 nanosec) oet
21102 (739 sec, 891470054 nanosec) lldff
140 (0 sec, 90282 nanosec) sfowe
123 0 sec, 324590 nanosec) xjjv
8939 (0 sec, 337230856 nanosec) asadj
19 (0 sec, 1455434 nanosec) sahjdi
210 (0 sec, 89131 nanosec) posdio
3 (0 sec, 3750149 nanosec) jhd
873 (260 sec, 715043557 nanosec) lppeuv
16 (0 sec, 212024 nanosec) hjass
13668 (2 sec, 506391927 nanosec) nnuua

# 6  
Old 05-20-2009
Vidyadhar85....your script doesn't work....
this is output...

$ awk -F"[( ]" '{printf "%f %s\n",($3+($5/1000000000))/$1,$NF}' test.txt|sort -r -k1 | more
awk: 0602-566 Cannot divide by zero.
The input line number is 19. The file is test.txt.
The source line number is 1.
0.000000 xjjv
0.000000 sjhfdf
0.000000 sfowe
0.000000 sahjdi
0.000000 posdio
0.000000 oet
0.000000 nnuua
0.000000 lppeuv
0.000000 lmhn
0.000000 lldff
0.000000 jhd
0.000000 hjass
0.000000 hijk
0.000000 efgh
0.000000 dkfi
0.000000 dfhjf
0.000000 asadj
0.000000 abcd
$
# 7  
Old 05-20-2009
@ summer_cherry
I dont understand your script.
How to run your script if I have to run it against file test.txt ?
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to create runtime variables based on the number of parameters passed in the script

Hi All, I have a script which intends to create as many variables at runtime, as the number of parameters passed to it. The script needs to save these parameter values in the variables created and print them abc.sh ---------- export Numbr_Parms=$# export a=1 while do export... (3 Replies)
Discussion started by: dev.devil.1983
3 Replies

2. Shell Programming and Scripting

wrapper script design for gnu ed text editor i/o

Hi. I'm having trouble writing a wrapper script for the command line text editor gnu ed. I want to be able to run the following algorithm on ed: 1. Display, on stdout, a command which I intend to feed into ed (before I actually feed it to ed). 2. Actually feed the command into ed's stdin.... (2 Replies)
Discussion started by: vomv1988
2 Replies

3. Programming

CGI Perl script to execute bash script- unable to create folder

Hi I have a bash script which takes parameters sh /tmp/gdg.sh -b BASE-NAME -n 1 -s /source/data -p /dest/data/archive -m ARC gdg.sh will scan the /source/data and will move the contents to /dest/data/archive after passing through some filters. Its working superb from bash I have... (0 Replies)
Discussion started by: rakeshkumar
0 Replies

4. Homework & Coursework Questions

Create script to add user and create directory

first off let me introduce myself. My name is Eric and I am new to linux, I am taking an advanced linux administration class and we are tasked with creating a script to add new users that anyone can run, has to check for the existence of a directory. if the directory does not exist then it has... (12 Replies)
Discussion started by: pbhound
12 Replies

5. Shell Programming and Scripting

Perl Question on How to Design an Effective Script

Hello All, This is my situation and I am new to perl scripting so I am trying to figure out the best way to tackle this problem. I need help in creating the logic to analyze the data. Problem: I need to access an oracle database, gather information from a specific query and then analyze... (0 Replies)
Discussion started by: jacktravine
0 Replies

6. Shell Programming and Scripting

To design a report using shell script

Short Description: To find the core files from a directory for the previous day and e-mail it across to a particular id. 1) Finding the core files in a directory. 2) The time is divided into eight fields and based on the time the respective field should be updated with the flag 1. ... (1 Reply)
Discussion started by: venkatesht
1 Replies

7. 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

8. Shell Programming and Scripting

Ksh script - Design ? - Search file and set variables

Hi - I'm trying to think of a clever way to write a shell script (trying to stay w/ ksh as that's what I know the best...) that will resolve the following problem: Problem - On a daily basis I have to email folks who are on-call to remind them. I was hoping to script this out so I could have... (9 Replies)
Discussion started by: littlefrog
9 Replies
Login or Register to Ask a Question