need to check code for #1 using linux vi editor ***************************** # Script to calculate percentage of upper-case letters to total number of alphas for a filename #!/bin/bash # Check if...

1 answer below »
need to check code for #1
using linux vi editor
*****************************


# Script to calculate percentage of upper-case letters to total number of alphas for a filename #!/bin/bash # Check if only one argument is given if [[ $# != 1 ]];then echo "Usage: assign5-1.sh text_file" > /dev/stderr exit 1 fi # Check if the argument is a file and readable if [[ ! -f $1 ]];then echo "Usage: assign5-1.sh text_file" > /dev/stderr exit 1 fi # Check if the file is not readable if [[ ! -r $1 ]];then echo "Usage: assign5-1.sh text_file" > /dev/stderr exit 1 fi UC_count=0 alpha_count=0 # Read the file while IFS= read -n1 char; do if [[ $char = [a-zA-Z] ]];then alpha_count=$(( alpha_count + 1 )) if [[ $char = [A-Z] ]];then UC_count=$(( UC_count + 1)) fi fi done


2.




# Script to get total file size in the current directory size=0 for file in $(ls .);do if [[ -f $file ]]; then tmp=$(ls -l $file | cut -d" " -f5) size=$(( size + tmp )) # Convert kilo bytes to bytes fi done echo "Total size = $size"




assign5_FL21 GlendaleCommunityCollege Due:November9,2021 UNIX/LinuxOperatingSystem Assignment5–Page1/1 1. (50 pts) Write a script to report the percentage of upper-case letters to the total number of alphas for a filename specified as an argument on the command line. Within your script, you will need to a) Verify that there is only one command line argument. Make sure that the single filename argument is a readable file. If the number of arguments is not correct, display a usage statement and exit the script with an appropriate exit value. If the argument is not a readable file, display an error message along with a usage statement before exiting with an appropriate exit value. Error messages must be sent to the stderr channel. b) Count the number of upper-case letters from this file and assign the result to the shell variable UC_count. c) Count the number of alphas from this file and assign the result to the shell variable alpha_count. d) Using the bc command with an appropriate scale factor, calculate the percentage of upper case alphas in the file. Avoid “divide by zero” errors. If the $alpha_count variable has a value of zero, display a specific message for that condition. e) Report the results with the following output format. $ assign5-1.sh /etc/passwd With a total of 239 alphas, /etc/passwd has 7.53% upper-case letters. $ echo $? 0 $ assign5-1.sh Usage: assign5-1.sh text_file $ echo $? 1 $ assign5-1.sh /etc Usage: assign5-1.sh text_file $ echo $? 1 $ assign5-1.sh /etc/passwd /etc Usage: assign5-1.sh text_file $ echo $? 1 $ assign5-1.sh /etc/shadow Error: cannot open /etc/shadow Usage: assign5-1.sh text_file $ echo $? 1 $ assign5-1.sh mbox With a total of 26692674 alphas, mbox has 51.92% upper-case letters. $ echo $? 0 $ assign5-1.sh empty_file With a total of 0 alphas, mbox has no upper-case letters. 2. (25 pts) Using only the commands from this set (ls, grep, cut, sed, tr, for, and expr), write a script to report the size (in bytes) of the sum of all the file sizes (plain files only) in the current directory. That’s *in* the current directory, not “in and below” the current directory. Hidden files may remain hidden. 3. (25 pts) Using only the commands ls and awk, write a script to report the size (in bytes) of the sum of all the file sizes (plain files only) in the current directory. That’s *in* the current directory, not “in and below” the current directory. Hidden files may remain hidden. Write your scripts using the template provided in the previous assignment. Submit the scripts via email [ [email protected]]. The subject line of the email must include “YourName GCCID assign5”.
Answered 1 days AfterNov 08, 2021

Answer To: need to check code for #1 using linux vi editor ***************************** # Script to calculate...

Swapnil answered on Nov 10 2021
107 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here