Requirements: Write a script that will determine which file in a directory has the maximum number of lines (this may be different than the file
Requirements:
Write a script that will determine which file in a directory has the maximum number of lines (this may be different than the file that has the maximum number of bytes). After determining the file with the maximum number of lines, the script will print out the name of the file and the number of lines. The script should only focus on files and ignore sub directories. Research the wc command options under the manual online documentation.
The maxlines.sh script is designed to handle zero (0) or one (1) argument(s).
o If zero arguments are specified, the script by default will examine the files in the current directory.
o If one argument is specified, the argument must be a valid directory name. The script will then examine the files in the specified directory.
The script should be able to handle the following error conditions:
o More than 1 argument is specified o The specified argument is not a directory.
The script file name must be: maxlines.sh
The script must be located in $HOME/itec400/homework
Make sure the permissions on the your itec400 directory are 705
Make sure the permissions on your script are 705
Sample Output Sunny Day Scenarios (note: output depends on current directory and may not match the values below): > maxlines.sh File maxlines.sh has maximum number lines ( 36 lines). At the system prompt>), enter the following on command line: maxlines.sh /export/home/dandrear/public_html/itec400/Misc/small_passwd File small passwd has maximum number lines 7 lines). Rainy Day Scenarios: > maxlines.sh junk error: argument must be a directory usage: maxlines.sh [directory] > maxlines.sh junk trash error: can only use 0 or 1 arguments. usage: maxlines.sh [directory] #!/bin/xxx # Script name:Imaxlines.sh # Case #1: ./maxlines.sh # Case #2: ./maxlines.sh/bin # Case #3: ./maxlines.sh # Functionality: This script reads each file in a directory and counts the # number of new lines. After determining this count, the file name and new # line count are saved. The new line count is then compared to each # file to determine the file with the highest new line count. # Output an error message because more than one argument is present on the # command line. ERRORI="error: can only use o or l arguments. usage: maxlines.sh [directory]" ERROR2="error: argument must be a directory. usage: maxlines.sh [directory] " # Verify that more than one command line argument doesn't exist. if [[ $* -gt x ]] then printf "SERRORI" exit i fi # Default to the current directory Case I and 3 DIR="." # Case #2 and 3. if [[ XX -eq i l] then # Is the directory entry a directory? if [[ XX $1 ]] then # Assign Variable DIR to command line directory. DIR="$ 1" else printf "SERROR2" exit i XX fi # All Cases are processed with the following code. cd SDIR FILE=$ (WC -1 13'2>/devull | sort -bx | tail -n X | head xx x) printf "File echo $FILE | awk '{print $2}' has the maximum lines with "echo $FILE | awk '{pri nt $1]' lines. " exit X -- INSERT -- 2,15 Sample Output Sunny Day Scenarios (note: output depends on current directory and may not match the values below): > maxlines.sh File maxlines.sh has maximum number lines ( 36 lines). At the system prompt>), enter the following on command line: maxlines.sh /export/home/dandrear/public_html/itec400/Misc/small_passwd File small passwd has maximum number lines 7 lines). Rainy Day Scenarios: > maxlines.sh junk error: argument must be a directory usage: maxlines.sh [directory] > maxlines.sh junk trash error: can only use 0 or 1 arguments. usage: maxlines.sh [directory] #!/bin/xxx # Script name:Imaxlines.sh # Case #1: ./maxlines.sh # Case #2: ./maxlines.sh/bin # Case #3: ./maxlines.sh # Functionality: This script reads each file in a directory and counts the # number of new lines. After determining this count, the file name and new # line count are saved. The new line count is then compared to each # file to determine the file with the highest new line count. # Output an error message because more than one argument is present on the # command line. ERRORI="error: can only use o or l arguments. usage: maxlines.sh [directory]" ERROR2="error: argument must be a directory. usage: maxlines.sh [directory] " # Verify that more than one command line argument doesn't exist. if [[ $* -gt x ]] then printf "SERRORI" exit i fi # Default to the current directory Case I and 3 DIR="." # Case #2 and 3. if [[ XX -eq i l] then # Is the directory entry a directory? if [[ XX $1 ]] then # Assign Variable DIR to command line directory. DIR="$ 1" else printf "SERROR2" exit i XX fi # All Cases are processed with the following code. cd SDIR FILE=$ (WC -1 13'2>/devull | sort -bx | tail -n X | head xx x) printf "File echo $FILE | awk '{print $2}' has the maximum lines with "echo $FILE | awk '{pri nt $1]' lines. " exit X -- INSERT -- 2,15Step by Step Solution
There are 3 Steps involved in it
Step: 1
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started