NDG Linux Essentials - Challenge Lab D: Pipes,
Redirection, and REGEX
Instructions
Case Scenario
A staff member has requested a list of the names of the services recognized by the current Linux image.
A file named /etc/services has been located that contains the pertinent information; however it is
not organized to easily determine all of the services.
Using a combination of pipes, redirects and control statements, produce output that contains only the
service names. The entire task must be accomplished without using any intermediary files. Each
service should only be listed once and captured to a file named [Link], located in the
home directory. Remove any blank lines or lines that are deemed to be comments.
There could be more than one possible solution for obtaining the desired results.
Objectives
Extract all the service names from the file.
Sort the names alphabetically removing any duplicates.
Remove any blank lines or lines that do not begin with a letter of the alphabet.
Capture the final output to a file named [Link].
Count the lines in the file using a conditional command that is only executed if the previous
combined commands are successful.
Curriculum Resources
Module 5 - Command Line Skills
Module 6 - Getting Help
Module 7 - Navigating the Filesystem
Deliverables
Provide the final command line for successful completion.
The final result should match the following:
340 [Link]
sysadmin@localhost:~$ head [Link]
acr-nema
afbackup
afmbackup
afpovertcp
afs3-bos
afs3-callback
afs3-errors
afs3-fileserver
afs3-kaserver
This study source was downloaded by 100000851532995 from [Link] on 05-03-2023 [Link] GMT -05:00
[Link]
afs3-prserver
sysadmin@localhost:~$ tail [Link]
zabbix-trapper
zebra
zebrasrv
zephyr-clt
zephyr-hm
zephyr-srv
zip
zope
zope-ftp
zserv
Answer Key
Below are screenshots of the commands that can be used to accomplish this lab, as well as the
commands used to verify the objectives.
sysadmin@localhost:~$ cut -d' ' -f1 /etc/services|cut -f1|sort -b -u|grep "^[A-Z
a-z]">[Link] && wc -l [Link]
340 [Link]
sysadmin@localhost:~$ head [Link]
acr-nema
afbackup
afmbackup
afpovertcp
afs3-bos
afs3-callback
afs3-errors
afs3-fileserver
afs3-kaserver
afs3-prserver
sysadmin@localhost:~$ tail [Link]
zabbix-trapper
zebra
zebrasrv
zephyr-clt
zephyr-hm
zephyr-srv
zip
zope
This study source was downloaded by 100000851532995 from [Link] on 05-03-2023 [Link] GMT -05:00
[Link]
zope-ftp
zserv
Both cut commands are necessary, since there are both spaces and tabs used for the field delimiter in
the /etc/services file.
Try the commands independently to see the results. Use of the man pages to explore the options
for cut, sort and grep.
This study source was downloaded by 100000851532995 from [Link] on 05-03-2023 [Link] GMT -05:00
[Link]
Powered by TCPDF ([Link])