Sponsored Content
Top Forums Shell Programming and Scripting Trouble with part of an exercise Post 302337897 by Franklin52 on Sunday 26th of July 2009 08:10:34 AM
Old 07-26-2009
To keep the forums high quality for all users, please take the time to format your posts correctly.

Use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)
Thanks.

The command of the BEGIN section executes before any input is read so the value of min is empty, to find the minimum size you can do something like this:

Code:
ls -l $1 | awk '
NR==2{
  min = $5; next
}
{
  if ($5 < min){
    min = $5;
  }
}
END {print "Tamanio menor fichero = " min; }'

Regards
 

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

[question] trouble with an 'exercise'

Hello guys.. well, im kinda newbie with unix because i started to learn it like 2 weeks ago. then i started to make some exercises, but i got stucked on this one : so, i need to know how many different 'names' has the 5th field and how many times each name appears. i was trying with a... (6 Replies)
Discussion started by: EnioMarques
6 Replies

2. UNIX for Dummies Questions & Answers

[question] hard exercise, help needed

Hello guys. Well, on this exercise i need the average "chargeAmount" per hour (for each hour). with this code : cat getusagesummarywrongmatch | grep -iv MOU2GRTObject | cut -d'|' -f4,14 | grep -i chargeamount | cut -d' ' -f2 http://img227.imageshack.us/img227/5889/65969235do0.jpg i got... (2 Replies)
Discussion started by: EnioMarques
2 Replies

3. Homework & Coursework Questions

Help with this exercise

you are to write a program which will read in a tax rate (as a percentage) and the prices of 5 items. the program is to calculate the total price, before tax, of the items and then the tax payable on those items, and then the total amount due. the tax payable is computed by appliying the tax rate... (1 Reply)
Discussion started by: bunkercrazy
1 Replies

4. Shell Programming and Scripting

A very tough exercise

hello everyone!:) I have an exercise which I think is difficult for beginner like me. Here is the exercise Create a shell script, which takes a directory as command line argument. Script displays ten first lines from every text file in that directory. After displaying the lines from the... (1 Reply)
Discussion started by: googlevn
1 Replies

5. Shell Programming and Scripting

[Solved] Printing a part of the last line of the specific part of a file

Hi, I have 80 large files, from which I want to get a specific value to run a Bash script. Firstly, I want to get the part of a file which contains this: Name =A xxxxxx yyyyyy zzzzzz aaaaaa bbbbbb Value = 57 This is necessary because in a file there are written more lines which... (6 Replies)
Discussion started by: wenclu
6 Replies

6. UNIX for Dummies Questions & Answers

UNIX Exercise

Hi, I am learning unix. I want to practice few small excercises. Please suggest me some goor URL to practice. Thanks in advance. (1 Reply)
Discussion started by: stew
1 Replies

7. Homework & Coursework Questions

Grades exercise

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Write a shell script program that will input a name and a mark between 0 and 100. The program then displays the... (9 Replies)
Discussion started by: UniverseCloud
9 Replies

8. UNIX for Beginners Questions & Answers

How to make a loop to read the input from a file part by part?

Hi All, We've a VDI infrastructure in AWS (AWS workspaces) and we're planning to automate the process of provisioning workspaces. Instead of going to GUI console, and launching workspaces by selecting individual users is little time consuming. Thus, I want to create them in bunches from AWS CLI... (6 Replies)
Discussion started by: arun_adm
6 Replies
MIN(3)									 1								    MIN(3)

min - Find lowest value

SYNOPSIS
mixed min (array $values) DESCRIPTION
mixed min (mixed $value1, mixed $value2, [mixed $...]) If the first and only parameter is an array, min(3) returns the lowest value in that array. If at least two parameters are provided, min(3) returns the smallest of these values. Note Values of different types will be compared using the standard comparison rules. For instance, a non-numeric string will be com- pared to an integer as though it were 0, but multiple string values will be compared alphanumerically. The actual value returned will be of the original type with no conversion applied. PARAMETERS
o $values - An array containing the values. o $value1 - Any comparable value. o $value2 - Any comparable value. o $... - Any comparable value. RETURN VALUES
min(3) returns the parameter value considered "lowest" according to standard comparisons. If multiple values of different types evaluate as equal (e.g. 0 and 'abc') the first provided to the function will be returned. EXAMPLES
Example #1 Example uses of min(3) <?php echo min(2, 3, 1, 6, 7); // 1 echo min(array(2, 4, 5)); // 2 // The string 'hello' when compared to an int is treated as 0 // Since the two values are equal, the order they are provided determines the result echo min(0, 'hello'); // 0 echo min('hello', 0); // hello // Here we are comparing -1 < 0, so -1 is the lowest value echo min('hello', -1); // -1 // With multiple arrays of different lengths, min returns the shortest $val = min(array(2, 2, 2), array(1, 1, 1, 1)); // array(2, 2, 2) // Multiple arrays of the same length are compared from left to right // so in our example: 2 == 2, but 4 < 5 $val = min(array(2, 4, 8), array(2, 5, 1)); // array(2, 4, 8) // If both an array and non-array are given, the array is never returned // as comparisons treat arrays as greater than any other value $val = min('string', array(2, 5, 7), 42); // string // If one argument is NULL or a boolean, it will be compared against // other values using the rule FALSE < TRUE regardless of the other types involved // In the below examples, both -10 and 10 are treated as TRUE in the comparison $val = min(-10, FALSE, 10); // FALSE $val = min(-10, NULL, 10); // NULL // 0, on the other hand, is treated as FALSE, so is "lower than" TRUE $val = min(0, TRUE); // 0 ?> SEE ALSO
max(3), count(3). PHP Documentation Group MIN(3)
All times are GMT -4. The time now is 08:57 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy