Write an awk program that works as below. a) It takes the name of a data file as
ID: 3825366 • Letter: W
Question
Write an awk program that works as below. a) It takes the name of a data file as parameter. The file is the output of the command ls -1 | tail -n +2 >lsfile Here is a sample content. -rw-r--r-- 1 cfs264sp170225 cfs264sp1702 21 2017-04-16 d1 drwxr-xr-x 2 cfs264sp170225 cfs264sp1702 4096 2017-04-16 dir1 -rw-r--r-- 1 cfs264sp 170225 cfs264sp1702 181 2017-04-16 lsfile -rwxr-xr-x 1 cfs264sp170225 cfs264sp1702 179 2017-04-16 p1 -rwxr-xr-x 1 cfs264sp170225 cfs264sp1702 14 2017-04-16 p2 -r-r-xr-x 1 cfs264spi 70225 cfs264sp1702 828 2017-04-16 signindata -rw-r--r-- 1 cfs264sp 170225 cfs264sp1702 210 2017-04-16 x b) The program prints (exactly once) an introductory text stating what it will do. c) The program prints the names of all files that were last updated on April 25, 2017. d) The program prints the number of files (from Step c) and total space occupied by the files (again, Step b) exactly once. For example, here is a possible display, which is for some imaginary data. Use the color codes to match items (b), (c), and (d) above to the display below. Here is the list of files updated on April 25, 2017 file1 logindata p1.pl p2.c Total space occupied by the above 4 files is 826. The program must be exclusively in awk and must be executable from the command line assuming access permissions are set. If you use additional Linux commands or a different language, you will not receive any credit for this problem. Here is an example of how the program is invoked. $ ./p3 lsfileExplanation / Answer
#!/bin/awk -f
BEGIN {
print "Here is the list of files updated on April 25, 2017";count = 0; size = 0
}
{
split($0, a, " ");
if (a[6] == "2017-04-25") {
print a[7];
count += 1;
size += a[5] ;
}
}
END { print "Total space occupied by the above " count " files is " size}
save this in a file p3
run chmod +x p3
then run it as provided in question.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.