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
  • Write a script using the bash shell to add new users to the system. The script...

    Write a script using the bash shell to add new users to the system. The script should read user information from a comma-delimited file (each field should be separated by a comma). The filename should be passed to the script as a command-line argument. Be sure the script contains a usage clause. The input file should contain the user information with one user per line. As the system administrator, you should determine the information necessary for each user to properly...

  • Hello I need help creating a bash script in linux for the following question: Create a...

    Hello I need help creating a bash script in linux for the following question: Create a script to expand the jpeg creator to create other types of files such as pdf, png, gif, etc. The jpeg creator is the following: #!/bin/bash FILE=$1 echo -e -n "\xFF\xD8\xFF\xE0"> $FILE dd if=/dev/random bs=512 count=4 >> $FILE

  • I need help with this. 1. In a bash shell script, what are the required elements...

    I need help with this. 1. In a bash shell script, what are the required elements of an "if" control structure? 2. In a bash shell script, what are the optional elements of an "if" control structure? 3. In a bash shell script, what are the required elements of a "while" control structure? 4. What is the difference between a shell variable and environment variable? Which one is considered local and which is considered global? 5. List the four kinds...

  • How do I write a bash shell script that encrypts a file by changing every letter...

    How do I write a bash shell script that encrypts a file by changing every letter except z to the next character in the alphabet. So a becomes b, b becomes c, and so on? z will be changed to a. Also, how do I write a bash shell script that reverses that?

  • I need a bash script that prompts the user for a filename within a directory, and...

    I need a bash script that prompts the user for a filename within a directory, and if the file/subdirectory exists to gzip them. Directories should be tarred and zipped, files should just be gzipped. This should poll inside of a loop to keep prompting the user until the user ends the script.

  • Hello all, I have a c++/unix (bash) question. I am struggling on starting this assignment. If...

    Hello all, I have a c++/unix (bash) question. I am struggling on starting this assignment. If you could start the assignment and tell me how to do the rest it would be greatly appreciated! (Quick thumbs up answer response if thorough and correct) Maintain automobile records in a database Write a shell script to create, view and modify a simple database that contains automobile records. The shell script has to be done in Bourne shell syntax (bash as a matter...

  • Hello, I need help creating a bash script for the following question, please also show screen...

    Hello, I need help creating a bash script for the following question, please also show screen shot of running the program, thank you for your help in advance Create a script to create files such as jpeg, pdf, png, gif, etc.

  • Hello I need help creating a bash script for linux as shown below getting the information...

    Hello I need help creating a bash script for linux as shown below getting the information from ifconfig The script must programmatically gather and output the informationEXACTLY AS SHOWN BELOW and (not echo this and echo that). ====================================== Interface: AAA MAC Address: BB:BB:BB:BB:BB:BB IP Address: CCC.CCC.CCC.CCC Subnet Mask: DDD.DDD.DDD.DDD Received Bytes: EEEEEE ====================================== Thanks,

  • How to write a bash shell script that prints a hollow box after user enters number...

    How to write a bash shell script that prints a hollow box after user enters number of lines, ie "bash hbox 4" , prints: **** *   * *   * **** My code doesnt work. i need it to take in the argument from the command line: ./hbox 4 "*" echo "Enter number of rows" read sz clear for (( x = 1; x <= $sz; x++ )); do     for (( y = 1; y <= $sz; y++ )); do...

  • Hello, I would greatly appreciate it if anyone could help me. I saved a text file...

    Hello, I would greatly appreciate it if anyone could help me. I saved a text file in the C drive of my computer. I need to use open the text file to do my homework. But when I used the Python 3.7 to open the file, I got error message: NO SUCH FILE OR DIRECTORY. What should I do to open the file using the Python. Many thanks for your help.

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