Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!