I would start with opening our script
and we have already written what should happen with an extension specified by user is not found.
So now in this part of code we know that user has specified some extension and we know that debt extension
exists in a location directory.
So we can now count the size of files of its specific extension.
And if you practice it in the last lecture.
So now we can write some command.
What we are going to do come the size of files with specific extension
so now pass output of ls l command for location variable
so pass it into oxcart awk program
and we will select only files that means that we will use only lines which starting with Desch and this
output will pass into up come on
and in that command we select the lines which ends with specific extension
and this output will help into another awk program.
And in the main section of that old program will count some.
So we can now create variable sum which will be incremented for each record by fifth field
but thats not all because we want to also know what is the largest and smallest file.
So we need to define variables min and max out to do that.
It would be good for first time for first record set into variables min and max value of fifth column
of the record and then for another record for another line we would compare a fifth on that value of
variable min and max.
So lets do that.
So for first record when a number of record is equal to 1 we can set a minimum to be value of Fifield
maximum Will we also value of Fifield and we can set value of nine field which is file name into variable
middle name
and the same.
We will do also for Max name.
So now the initial setting is done and we can compare
if value of Fifield is greater than value of variable mocs we will assign new value to variable Max
as value is bigger
and also V-Star new value into variable Max name
and now we can do the same
for case when in summary court will be value of field less then value of mean variable.
So in that case mean a variable will have to that variable assign value of Fifield and to variable name
Leavell assign value of nine field.
And we have basically finished Main awk section which is done for all our records.
In our case for each line of our command where are displayed only files of specific extension but we
should also bring to user what is the actual disk size of those files.
So in the end section when everything is counted we can print some
sold us government print and print the actual song
and we can display it in megabytes.
So due to division by one thousand twenty four two times
and we can also print how many files with specific extension is present using number of records of variable
so right files and news variable and our present number of records and that's all we go line by line
and checking if Fifield of each line is greater than maximum or if it is less than the minimum.
And if yes we are setting a new values to variables min and max at the end.
We are printing what is the actual sum and how many files of it specific extension are present.
We can save the script and run it specify some location and some existing extension
and it is working.
The actual size.
And how many files of its specific extension is present in that specified directory great.
Now we use some not existing extension.
Good.
We see that no file with the set extension was found.
It is working well.
But if we don't specify any extension we don't see any sum for a specified directory.
And also we don't have the logic for printing statistics so we need to fix it all in the next election.