Sponsored Content
Top Forums Shell Programming and Scripting Improve program efficiency (awk) Post 302338275 by danmero on Monday 27th of July 2009 11:48:50 AM
Old 07-27-2009
I will try Smilie
Code:
# awk --version
awk version 20070501 (FreeBSD)

# ls -l |awk '{
                   min=min?min:$5                          # Set min=min if min exist, if not set min=$5
              }
                  {
                    if(min>$5) min=$5                      # Asign $5 value to min if min is greater that $5 
                    if(max<$5) max=$5                      # Asign $5 value to max if $5 is greater that max 
                    suma+= $5                              # Addition 5th field value to suma variable
                   }
END    {
           printf "min=%d max=%d suma=%d", min,max,suma    # Format output for eval
         }
'

 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

efficiency..

how efficient is it, and how practical is it to call outside programs in a shell script (bash) for small tasks? for example, say i have a script that might preform many tasks, one of those tasks may require root access; rather than implementing inside the script a method to use su or sudo to... (11 Replies)
Discussion started by: norsk hedensk
11 Replies

2. Shell Programming and Scripting

Perl: code efficiency for gmtime

I have the following Perl snippet: # get datetime @dt = gmtime(); $strdate = 1900 + $dt . addleadingzero(++$dt) . addleadingzero($dt) . addleadingzero($dt) . addleadingzero($dt) . addleadingzero($dt); # write to file $outfile = $strdate . ".txt"; getstore($url, $outfile) or die "Error:... (3 Replies)
Discussion started by: figaro
3 Replies

3. Shell Programming and Scripting

Problem with awk awk: program limit exceeded: sprintf buffer size=1020

Hi I have many problems with a script. I have a script that formats a text file but always prints the same error when i try to execute it The code is that: { if (NF==17){ print $0 }else{ fields=NF; all=$0; while... (2 Replies)
Discussion started by: fate
2 Replies

4. Shell Programming and Scripting

The efficiency between GREP and SED???

Hello Everyone! I am a newbie. I'd like to get key lines from a big txt file by Reg Exp, The file is nearly 22MB. GREP or SED?which may be the best choice,more efficient way? or any other best practise? Thank you in advance. Ever:) (5 Replies)
Discussion started by: ever
5 Replies

5. Shell Programming and Scripting

Improve performance of echo |awk

Hi, I have a script which looks like this. Input file data1^20 data2^30 #!/bin/sh file"/home/Test.txt" while read line do echo $line |awk 'BEGIN { FS = "^" } ; { print $2 }' echo $line |awk 'BEGIN { FS = "^" } ; { print $1 }' | gzip | wc -c done <"$file" How can i... (4 Replies)
Discussion started by: chetan.c
4 Replies

6. Shell Programming and Scripting

Looking to improve the output of this awk one-liner

I have the following awk one-liner I came up with last night to gather some data. and it works pretty well (apologies, I'm quite new with awk, and don't know how to format this pretty-printed). You can see the output with it. awk '{if ($8 == 41015 && $21 == "requests") arr+=$20;if ($8 == 41015... (3 Replies)
Discussion started by: DeCoTwc
3 Replies

7. Shell Programming and Scripting

File or Folder Efficiency?

I've got this program set up so that it creates files whose unique names specify the jobs their contents describe. In order to retrieve the information inside those files, I have to do a "grep" and awk or sed to extract it. I've just assumed that making a directory with that unique name that... (1 Reply)
Discussion started by: gmark99
1 Replies

8. Shell Programming and Scripting

Improve awk code that has three separate parts

I have a very inefficient awk below that I need some help improving. Basically, there are three parts, that ideally, could be combined into one search and one output file. Thank you :). Part 1: Check if the user inputted string contains + or - in it and if it does the input is writting to a... (4 Replies)
Discussion started by: cmccabe
4 Replies

9. UNIX for Advanced & Expert Users

About efficiency of parallel memory allocation

Hello, there. I'm a new beginner to Linux kernel and curious about its memory management. When multiple applications apply for memory space at the same time, how Linux kernel solve the resource contending problem for high performance? I have known that there is a buddy system for allocating and... (4 Replies)
Discussion started by: blackwall
4 Replies
mlib_VectorMinimumMag_U8C(3MLIB)			    mediaLib Library Functions				  mlib_VectorMinimumMag_U8C(3MLIB)

NAME
mlib_VectorMinimumMag_U8C, mlib_VectorMinimumMag_S8C, mlib_VectorMinimumMag_S16C, mlib_VectorMinimumMag_S32C, mlib_VectorMinimumMag_F32C, mlib_VectorMinimumMag_D64C - find the first element with the minimum magnitude in a vector SYNOPSIS
cc [ flag... ] file... -lmlib [ library... ] #include <mlib.h> mlib_status mlib_VectorMinimumMag_U8C(mlib_u8 *min, const mlib_u8 *x, mlib_s32 n); mlib_status mlib_VectorMinimumMag_S8C(mlib_s8 *min, const mlib_s8 *x, mlib_s32 n); mlib_status mlib_VectorMinimumMag_S16C(mlib_s16 *min, const mlib_s16 *x, mlib_s32 n); mlib_status mlib_VectorMinimumMag_S32C(mlib_s32 *min, const mlib_s32 *x, mlib_s32 n); mlib_status mlib_VectorMinimumMag_F32C(mlib_f32 *min, const mlib_f32 *x, mlib_s32 n); mlib_status mlib_VectorMinimumMag_D64C(mlib_d64 *min, const mlib_d64 *x, mlib_s32 n); DESCRIPTION
Each of these functions finds the first element with the minimum magnitude in a complex vector, then puts the real and imaginary parts of it into min[0] and min[1], respectively. PARAMETERS
Each of the functions takes the following arguments: min Pointer to the first element with the minimum magnitude. x Pointer to the first element of the source vector. n Number of elements in the source vector. RETURN VALUES
Each of the functions returns MLIB_SUCCESS if successful. Otherwise it returns MLIB_FAILURE. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Committed | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ SEE ALSO
mlib_VectorMaximumMag_U8C(3MLIB), mlib_MatrixMaximumMag_U8C(3MLIB), mlib_MatrixMinimumMag_U8C(3MLIB), attributes(5) SunOS 5.11 2 Mar 2007 mlib_VectorMinimumMag_U8C(3MLIB)
All times are GMT -4. The time now is 05:08 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy