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

Using only the following UNIX commands: grep, ls, cat and wc, develop a single c

ID: 3880790 • Letter: U

Question

Using only the following UNIX commands: grep, ls, cat and wc, develop a single command line (regular expressions) to perform the task required. You dont need to use all commands

a) Print all the words in for example a dictionary file that start with un and end with ix. This includes the word unix itself.

(b) Find all the words in a dictionary file that contain all four lower-case characters that appear in the word “unix” (i.e. ‘u’, ‘n’, ‘i’, and ‘x’) in alphabetical order. For example, influx is such a word, but unfix is not.

(c) Print a single integer that is the number of 6-character words in for example a dictionary file that start with can and end with either a or c. For example, canada is such a word, but canzona, cancel and camera are not.

Explanation / Answer

a) grep command is used to get all the words that starts with 'un' and ends with 'ix' in file name dictionary.

grep ^un ix$ dictionary

b) cat comaand is pipelined with multiple grep command to to find all words containing characters 'u', 'n', 'i', 'x'.

cat dictionary | grep | i | grep n | grep u | grep x

c) 2 grep command are pipelined to get all the words that are starting with 'can' and ending with either 'a' or 'c' and contains 6 characters.

cat dictionary | grep -x '.{6}' | grep ^can 'a | c'$

grep

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote