Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the Example code: #!/bin/sh PREVWORD=BEGIN tr -c a-zA-Z ' ' | grep '[a-zA-Z]' | while read WORD do echo $PREVWORD $WORD PREVWORD=$WORD done This

Consider the Example code:

#!/bin/sh

PREVWORD="BEGIN"

tr -c "a-zA-Z" ' ' | grep '[a-zA-Z]' | while read WORD

do

echo "$PREVWORD $WORD"

PREVWORD="$WORD"

done

This code converts anything that isnt a letter into a newline, returns only lines with letters, and read returns a word at a time into the variable WORD . For example, running the script:

$ echo "The cat in the hat" | ./words.sh

BEGIN The

The cat

cat in

in the

the hat

Use the sample script above to write a script in Linux Bash. the script is words.sh that generate a list of four word sequences only from the input it is given.

for example, given a text file input.txt that contains the words: "The John is pretty full right now"

we run:

$ ./words.sh < input.txt > input.txt $ tail -n 4 input.txt

and we get output as:

The John is pretty

John is pretty full

is pretty full right

pretty full right now

Rules:

- must work with stdin/stdout

- must work with one character words such as i and a

- all other words accounted for must be at least two characters and contain a vowel

- must be all lowercase (use tr)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

3 How the market system answers four fundamental questions.

Answered: 1 week ago