Question: Part 1 Requirements The shell script srchfile.sh must accept exactly two arguments. o The script shall first print the name of the file being searched.

Part 1 Requirements

The shell script srchfile.sh must accept exactly two arguments.

o The script shall first print the name of the file being searched.

o If there are one more instances of the string in the file, the script shall print each line that contains the matching string, along with the line number of the file. You may use the UNIX command grep in your script to do the actual search. In fact, grep can even print the line number if used with the appropriate option (see man page for grep).

If the user enters more or less than the required number of arguments, the script shall produce an error message and stop.

The first argument shall represent the string to be searched.

The second argument represents the name of the file to be searched. If the second argument is not a file, the script shall produce an error message and stop.

The script file name must be: srchfile.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

Part 1 Requirements The shell script srchfile.sh must accept exactly two arguments.

***Please use the template below - replace X***

o The script shall first print the name of the file being

Sample Output Sunny Day scenario, searching for string "if" in file "ex0210" in "examples" directory: Sample coup de moi > srchfile.sh if /export/home/dandrear/public html/itec400/examples/ex0210 ------ File = /export/home/dandrear/public_html/itec400/examples/ex0210 ------ 6:if [ "$LOGNAME" = "dandrear" 1 10:if [ "ls wc-1'"-ne 0 ] 14:if [ -w $PWD] Rainy Day scenario, script is invoked with only one argument: > srchfile.sh if error: must provide 2 arguments. usage: srchfile.sh search-pattern file Rainy Day scenario, searching for "if" in a directory: > srchfile.sh if /etc error: second argument must be a file. usage: srchfile.sh search-pattern file XXX/ksh # Script name: srchfile.sh # Functionality: Search for a given string within a specified file. # Case #1: ./srchfile.sh if [ $# -gt 2 ] then echo "error: must provide 2 arguments" echo "usage: $0 search-pattern file" #XXXX [ $# -lt 2 ] then echo "error: must provide 2 arguments" echo "usage: $0 search-pattern file" elif [ -f $2 ] #XXXX echo "------ File = $2 ------" OUTPUT="egrep -in $X $X echo "$OUTPUT" else echo "error: second argument must be a file" echo "usage: $0 search-pattern file

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!