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

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

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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
