Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Simple Shell Scripting For Linux - Please replace the XXXs in the script below to solve this: Write a script that will determine which file

Simple Shell Scripting For Linux - Please replace the XXXs in the script below to solve this:

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 onlyfocus 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).

If zero arguments are specified, the script by default will examine the files in the current directory.

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:

More than 1 argument is specified

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

Maxlines.sh script logic:

#!/bin/ksh

# Script name: maxlines.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.

ERROR1="error: can only use 0 or 1 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.

XX [[ XX -gt 1 ]]

then

printf "$ERROR1"

exit 1

fi

# Default to the current directory Case 1 and 3

DIR="."

# Case #2 and 3.

XX[[ $# -eq X ]]

then

# Is the directory entry a directory?

if [[ XX $1 ]]

then

# Assign Variable DIR to command line directory.

DIR="$1"

else

printf "$ERROR2"

exit 1

fi

fi

# All Cases are processed with the following code.

cd $DIR

FILE=$(wc -l `ls` 2>/dev/null | sort XXX | tail XXX | head XXX)

printf "File `echo $FILE | awk '{print $2}'` has the maximum lines with `echo $FILE | awk '{print $1}'` lines. "

exit X

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Flash XML Applications Use AS2 And AS3 To Create Photo Galleries Menus And Databases

Authors: Joachim Schnier

1st Edition

0240809173, 978-0240809175

More Books

Students also viewed these Databases questions

Question

Define organisational structure

Answered: 1 week ago

Question

Define line and staff authority

Answered: 1 week ago

Question

Define the process of communication

Answered: 1 week ago

Question

Explain the importance of effective communication

Answered: 1 week ago

Question

* What is the importance of soil testing in civil engineering?

Answered: 1 week ago

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago