Question

Hello, I am attempting to write a basic shell script using bash. It will need to...

Hello, I am attempting to write a basic shell script using bash. It will need to print the user, host, time, and date. It will need to take user input for a txt file to be searched and create a new file to save the results. It must print the number of lines and characters in the text. The user will need to enter three words to be searched, and the number of occurrences of those words in the text will be reported. Then, a comparison will be made displaying the words in order from greatest to least.

I am running putty on windows and using the pico editor. If anyone could help me get started I would greatly appreciate it. Thank you.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#!/bin/bash

echo "Username: " `whoami`
echo "Host: " `hostname`
echo "Date & Time: " `date`

echo
echo "Enter file name to search "
read fn

echo
echo "Number of lines in file $fn are : " `wc -l $fn`
echo "Number of characters in file $fn are: " `wc -c $fn`

echo
echo "Enter three word to search in file $fn 1 : "
read sr1

echo
echo "Enter three word to search in file $fn 2 : "
read sr2

echo
echo "Enter three word to search in file $fn 3 : "
read sr3

result1=`grep $sr1 $fn -o | wc -l`
result2=`grep $sr2 $fn -o | wc -l`
result3=`grep $sr3 $fn -o | wc -l`

echo
echo "result 1 of word $sr1 : " $result1 > result.txt
echo "result 2 of word $sr2 : " $result2 >> result.txt
echo "result 3 of word $sr3 : " $result3 >> result.txt

cat result.txt | sort -r

rm -rf result.txt


if you have any doubt then please ask me without any hesitation in the comment section below , if you like my answer then please thumbs up for the answer , before giving thumbs down please discuss the question it may possible that we may understand the question different way and we can edit and change the answers if you argue, thanks :)

Add a comment
Know the answer?
Add Answer to:
Hello, I am attempting to write a basic shell script using bash. It will need to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT