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

Help answering questiosn I am using a non-gui red hat unix (Linux version 2.6.18

ID: 3848047 • Letter: H

Question

Help answering questiosn

I am using a non-gui red hat unix (Linux version 2.6.18-419.el5 (mockbuild@x86-027.build.eng.bos.redhat.com) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-55)) #1 SMP Wed Feb 22 22:40:57 EST 2017)

1. Use egrep and a regular expression to find all the words in /usr/share/dict/words that consist entirely of lowercase letters.

2. Use egrep and a regular expression to find all the movies in /tmp/bette.txt that have at least one repeated uppercase letter, such as The Watcher in the Woods (1980). (Note the two occurrences of W.)

3. Use egrep and a regular expression to find the one word in /usr/share/dict/words that has ELEVEN consecutive consonants, regardless of case.

4. Use egrep and a regular expression to find the one word in /usr/share/dict/words that starts and ends with the same eight characters.

5. Use egrep and a regular expression to find all the all-vowel (regardless of case) words in /usr/share/dict/words.

6. Use egrep and a regular expression to find the one word in /usr/share/dict/words that is composed entirely of 8 consonants (regardless of case)

7. Use egrep and a regular expression to find all the entries in /etc/passwd for those users whose first name as listed (in the name field) begins with a V or v.

I HAVE TRIED

1. egrep '^[a-z]$' /usr/share/dict/words

2. egrep '(w[A-Z]){2,}' /tmp/bette.txt

3. egrep -o '[^aeiouAEIOU]+[^aeiouAEIOU]+[^aeiouAEIOU]+[^aeiouAEIOU]+[^aeiouAEIOU]+[^aeiouAEIOU]+[^aeiouAEIOU]+[^aeiouAEIOU]+[^aeiouAEIOU]+[^aeiouAEIOU]+[^aeiouAEIOU]' /usr/share/dict/words

4. egrep '<([a-zA-Z]){8,}*([a-zA-Z]){8,}>' /usr/share/dict/words

5. egrep'<[aeiouAEIOU]>' /usr/share/dict/words

6. egrep -o '<[^aeiouAEIOU]+[^aeiouAEIOU]+[^aeiouAEIOU]+[^aeiouAEIOU]+[^aeiouAEIOU]+[^aeiouAEIOU]+[^aeiouAEIOU]+[^aeiouAEIOU]>' /usr/share/dict/words

7. egrep '^[vV]*' /etc/passwd

AND

1. grep -e ' "[[:lower:]] +" ' file

And grep [a-z] file

5. grep '[aeiouAEIOU]'

And

grep -vE '^([^a]*|[^e]|*[^i]*|[^o]*|[^u]*)$*' file

7. grep -i '^v' file

Or grep '^v' file

Or grep '^V' file

none are working

Explanation / Answer

Ans)
1. Use egrep and a regular expression to find all the words in /usr/share/dict/words that consist entirely of lowercase letters.
A)

egrep '^[a-z]*$' /usr/share/dict/words

Here you need to use [a-z]* to match all the lowercase words. To restrict matching to only lowercase letter words we have to use '^[a-z]*$' indicating match words whose first letter, successive letter and ending letter should only be lowercase letters.

2. Use egrep and a regular expression to find all the movies in /tmp/bette.txt that have at least one repeated uppercase letter, such as The Watcher in the Woods (1980). (Note the two occurrences of W.)
A)
command is : egrep '([A-Z]).*(.*){1,}' /tmp/bette.txt

I dont have /tmp/bette.txt so i created similar file in my system and below are their entries.
Unix Terminal> cat /tmp/bette.txt
The Watcher in the Woods (1980)
Training the Dragon
Enter the Dragon
Beauty and the Beast
The Fate of the Furious
Pirates of the Caribbean: Dead Men Tell No Tales
The Fate of the Furious The Fate of the Furious

Unix Terminal> egrep '([A-Z]).*(.*){1,}' /tmp/bette.txt
The Watcher in the Woods (1980)
Beauty and the Beast
The Fate of the Furious
Pirates of the Caribbean: Dead Men Tell No Tales
The Fate of the Furious The Fate of the Furious
Unix Terminal>

To match an upper case letter followed by 3 repeated occurrences of it which is 'F' here
Unix Terminal> cat /tmp/bette.txt |egrep '([A-Z]).*(.*){3,}'
The Fate of the Furious The Fate of the Furious


Explanation:
([A-Z]) - matches uppercase letter and captures the matched uppercase character in 
.* - represents any number of characters
 - represents the repeated matched character which is ([A-Z])
(.*) - represents the repeated matched character followed by any character
(.*){1,} - represents the repeated matched character followed by any character can occur atleast once or more than that.


3. Use egrep and a regular expression to find the one word in /usr/share/dict/words that has ELEVEN consecutive consonants, regardless of case.
A)

The consonants in english are B, C, D, F, G, H, J, K, L, M, N, P, Q, R, S, T, V, X, Z, and usually W and Y. These are can also be called as non-vowels. Given that we can write a regular expression to match all non-vowels which is like [^aeiouAEIOU] where ^ stands for negation that means it includes all characters except "aeiouAEIOU" which is nothing but consonants.

I dont find any words in /usr/share/dict/words with 11 consecutive consonants but i could find some words with 9, 10 consecutive characters which i have listed below. You can try the same commands in your system.

Unix Terminal> egrep '[^aeiouAEIOU]{9}' /usr/share/dict/words
Amblyrhynchus
glycyphyllin
Oxyrrhyncha
oxyrrhynchid
pachyrhynchous
Unix Terminal> egrep '[^aeiouAEIOU]{10}' /usr/share/dict/words
Amblyrhynchus
glycyphyllin
Unix Terminal> egrep '[^aeiouAEIOU]{11}' /usr/share/dict/words
Unix Terminal>

4. Use egrep and a regular expression to find the one word in /usr/share/dict/words that starts and ends with the same eight characters.
A)

egrep '^([a-z[A-Z]{8}).*$' /usr/share/dict/words is the command

I cannot find entries in words file in my system so i have created a test file like below. Please verify the same command in your system.

Unix Terminal> cat /tmp/test
hamham
hamburhambur
hamburgehamburge
hamburgehowarehamburge

I have tested on the above test file to find words that start and end with the same eight, six, three characters.
Unix Terminal> egrep '^([a-z[A-Z]{8}).*$' /tmp/test
hamburgehamburge
hamburgehowarehamburge
Unix Terminal> egrep '^([a-z[A-Z]{6}).*$' /tmp/test
hamburhambur
Unix Terminal> egrep '^([a-z[A-Z]{3}).*$' /tmp/test
hamham

Here is the explanation of regular expression.
[a-z[A-Z]{8} - sequence of 8 characters
([a-z[A-Z]{8}) - using parentheses ( and ) we are capturing 8 characters
^([a-z[A-Z]{8}) - starting with the sequence of 8 characters
.* - stands for any number of characters
 - represents what is captured in parentheses.
^([a-z[A-Z]{8}).*$ - here the starting eight character sequence is captured in parentheses which can be referred by . So we are saying starting with eight sequence of characters followed by any number of characters then the same sequence of eight characters in the starting has to be available at the end of word.

5. Use egrep and a regular expression to find all the all-vowel (regardless of case) words in /usr/share/dict/words.
A)

Unix Terminal> egrep '^[aeiouAEIOU]*$' /usr/share/dict/words
A
a
aa
ae
ai
Ao
E
e
ea
eu
euouae
I
i
iao
ie
Io
io
O
o
oe
oii
U
u
Unix Terminal>

Here is the explanation:
[aeiouAEIOU] - matches only vowels both upper and lower case
^[aeiouAEIOU]*$ - matches any words beginning with a vowel followed by and ends with vowels

6. Use egrep and a regular expression to find the one word in /usr/share/dict/words that is composed entirely of 8 consonants (regardless of case)
A)

Unix Terminal> egrep '^[^aeiouAEIOU]{8}$' /usr/share/dict/words
symphysy

Here is the explanation:
[^aeiouAEIOU] - matches all non-vowels that is consonants
[^aeiouAEIOU]{8} - all non-vowels/consonants with 8 character length
^[^aeiouAEIOU]{8}$ - all consonants with 8 character length exactly

7. Use egrep and a regular expression to find all the entries in /etc/passwd for those users whose first name as listed (in the name field) begins with a V or v.
A)
the command is : egrep '^[vV]' /etc/passwd

It indicates the first character must be either v or V. In my /etc/passwd i dont have any firstname with v or V so i have tested the same with other users and it works fine.

sh-4.3$ cat /etc/passwd                                                                                                              
root:x:0:0:root:/root:/bin/bash                                                                                                      
bin:x:1:1:bin:/bin:/sbin/nologin                                                                                                     
daemon:x:2:2:daemon:/sbin:/sbin/nologin                                                                                              
adm:x:3:4:adm:/var/adm:/sbin/nologin                                                                                                 
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin                                                                                             
sync:x:5:0:sync:/sbin:/bin/sync                                                                                                      
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown                                                                                         
halt:x:7:0:halt:/sbin:/sbin/halt                                                                                                     
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin                                                                                       
operator:x:11:0:operator:/root:/sbin/nologin                                                                                         
games:x:12:100:games:/usr/games:/sbin/nologin                                                                                        
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin                                                                                          
nobody:x:99:99:Nobody:/:/sbin/nologin                                                                                                
systemd-timesync:x:999:998:systemd Time Synchronization:/:/sbin/nologin                                                              
systemd-network:x:998:997:systemd Network Management:/:/sbin/nologin                                                                 
systemd-resolve:x:997:996:systemd Resolver:/:/sbin/nologin                                                                           
systemd-bus-proxy:x:996:995:systemd Bus Proxy:/:/sbin/nologin                                                                        
dbus:x:81:81:System message bus:/:/sbin/nologin                                                                                      
apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin                                                                                 
cg:x:1000:1000::/home/cg:/bin/bash                                                                                                   
sh-4.3$                                                                                                                              
sh-4.3$ egrep '^[vV]' /etc/passwd                                                                                                    
sh-4.3$ egrep '^[sS]' /etc/passwd                                                                                                    
sync:x:5:0:sync:/sbin:/bin/sync                                                                                                      
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown                                                                                         
systemd-timesync:x:999:998:systemd Time Synchronization:/:/sbin/nologin                                                              
systemd-network:x:998:997:systemd Network Management:/:/sbin/nologin                                                                 
systemd-resolve:x:997:996:systemd Resolver:/:/sbin/nologin                                                                           
systemd-bus-proxy:x:996:995:systemd Bus Proxy:/:/sbin/nologin                                                                        
sh-4.3$ egrep '^[aA]' /etc/passwd                                                                                                    
adm:x:3:4:adm:/var/adm:/sbin/nologin                                                                                                 
apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin                                                                                 
sh-4.3$