Regex: Please provide a UNIX command for each of the following: 1. To start, her
ID: 3703388 • Letter: R
Question
Regex:
Please provide a UNIX command for each of the following:
1. To start, here is a simple puzzle. What are all the English words that begin with “qu” and ending with “y”. [Hint: Remember that each line of the dictionary file contains only a single word.]
2. The next puzzle is an old one. Find a common English word that contains all five vowels – a, e, i, o, u – in that order. The letters do not have to be adjacent, but they must be in alphabetical order. That is, “a” must come before “e”, which must come before “i”, and so on.
3. Our last puzzle involves a search of the Unix file system for historical artifacts. Many of the original Unix commands were two letters long; the text editor was ed, the copy program was cp, and so on. Let us find all such commands. To solve the puzzle, you need to know that the very oldest Unix programs reside in the /bin directory. There are other old Unix command in /usr/bin. Be sure to also provide a count of how many such commands there are.
Explanation / Answer
---the English words that begin with “qu” and ending with “y”.
grep -Ei 'qu.*y' new_sample_examples.txt
---Find a common English word that contains all five vowels – a, e, i, o, u – in that order.
grep -iE '[^aeiou]*a[^aeiou]*e[^aeiou]*i[^aeiou]*o[^aeiou]*u.*' new_sample_examples.txt
--Our last puzzle involves a search of the Unix file system for historical artifacts. Many of the original Unix commands were two letters long
Using / as field separator,
Finding filename $NF (last field)
Computing length
And check if value is 2, then print it.
--find files
find /bin /usr/bin -type f -print| awk -F/ ' length($NF) == 2 '
--to find count
find /bin /usr/bin -type f -print| awk -F/ ' length($NF) == 2 ' | wc -l