Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Develop a bash script which can accomplish the following tasks: -This program ha

ID: 3687264 • Letter: D

Question

Develop a bash script which can accomplish the following tasks: -This program has two arguments. The first one is a word, the second one is a path. -This program searches all files in the given path, and check whether the file name contains the given word. -If the file name contains the given word, output this file name to standard output (screen) and ask user whether need delete this file. -User can input "y" to delete this file and "n" to ignore this deletion -Use a loop to check all files given path. input, output example: ./part6.sh foo . .foo.txt Do you want to remove this file? [y/n] y food.txt Do you want to remove this file? [y/n] n ...

Explanation / Answer

Answer for Question:

This below bash script will read the full file path and word
then it will check the word is presented in the given list of path or not ..

This below bash script may help you to solve the given problem statement..


#!/bin/bash
echo -e "Enter the file name:"
read fi
echo -e "Enter the full path:"
read pa
se=$(find "$pa" -type f -name "$fi")
co=$(cat $se | wc -l)
if [ $co -eq 0 ]
then
echo "File not found on current path"
else
echo "Total file found: $co"
echo "File(s) List:"
echo "$se"
echo -e "Enter the word which you want to search:"
read wa
sea=$(grep -rHn "$wa" $se)
if [ $? -ne 0 ]
then
echo "Word not found"
else
echo "File:Line:Word"
echo "$sea"
fi
fi