Chapter 5 Cumulative Review

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

The ____ option of the diff command ignores blanks that repeat.

-b

The ____ option of the diff command shows lines surrounding the line that differs.

-c

You are using the grep command, but it is only searching through files in your immediate home directory. What option enables you to search through subdirectories below your home directory?

-r

The ____ option of the grep command displays only lines that do not contain the search pattern.

-v

Which of the following are examples of manipulation and transformation commands? (Choose all that apply.)

. sed, b. pr, c. join, and d. paste

One way to run a shell script is to make it executable by using the x permission and then typing ____ prior to the script name when you run the script itself.

./

When you enter the command grep Linux /info/Linux_features | head, what is the maximum number of lines that will be displayed?

10 lines

By default, pr formats the specified files into single-column pages of ____ lines.

66

Use a command to remove the letters "o" and "a" from the my_list file you created in the Hands-on Projects—and write the output to the file changed_list.

: First, type tr -d "oa" < my_list > changed_list and press Enter.

Use a command to find the instances in which the word "host" is used in the /etc directory

: Type grep host /etc/* and press Enter.

What addition to the command you used in Exercise 1 can you use to slow the output to one screen at a time?

Add a pipe and use more or less, as in grep host /etc/* | more or grep host /etc/* | less.

Create a new file, CD_list, and enter these lines in the file: country:1000:210 rock:1001:380 classical:1002:52 alternative:1003:122 light rock:1004:151 light rock:1004:151 celtic:1005:44 jazz:1006:62 soundtracks:1007:32 soundtracks:1007:32 Use the sed command and a script file to add these lines to the end of the CD_list file: hard rock:1008:70 misc:1009:22

After you create the file CD_list and the script file (see file CD_more file information below) type sed -f CD_more CD_list | cat > CD_list and press Enter. To create the CD_more file enter vi CD_more and type in the following lines: $a\ hard rock:1008:70\ misc:1009:22

. List four examples of selection commands.

Any four of the following (from this and previous chapters and from Table 5-1): comm, cut, diff, grep, head, tail, uniq, and wc.

____ is a full-featured programming language.

Awk

View the first 20 lines of /etc/termcap. Next, use a command to change all characters in "version" to upper case for only the first 20 lines in /etc/termcap.

First, type head -n 20 /etc/termcap and press Enter. Next, type, head -n 20 /etc/termcap | tr 'version' 'VERSION' and press Enter.

You want to create a file of your friends and relatives' names, addresses, telephone numbers, and other information. When you mention this to your sister-in-law, she recommends having separate fields for the first, middle, and last names. Briefly explain why this is a good idea.

Having separate fields for first, middle, and last names is a good idea because the last name can serve as a key, if you later decide to build other files related to friends and family. This format also enables you to sort the file, such as by last name, and to more easily pull out selected records from the file, such as for printing labels for specific people.

Which of the following is true of the pipe operator? (Choose all that apply.)

It redirects the output of one command to the input of another command

Bash is a freeware derivative of the Bourne and ____ shells.

Korn

When you use the pr command how can you limit the output to only a screen full of text to view. (Choose all that apply.)

Pipe the output into more. and c. Use the -l 23 option..

Your software has a bug in that it enables you to create a vendors file in which there are duplicate entries of vendors. Which of the following methods enables you to remove the duplicate vendors in this text file?

Sort the file and then use the uniq command to remove the duplicates, inputting the result in a new file

Briefly explain what you can accomplish with the sed command

The sed command can be used to edit the contents of one or more files. It enables you to delete lines, substitute text, append text, and show line numbers, for example. You can use one of two forms of sed, One form uses an editing command and the other uses a script file..

. Use a command to compare the trees and more_trees files and show the differences in terms of individual lines that differ.

Type diff trees more_trees and press Enter.

Use the grep command to find all the lines that contain the word "celtic" in the CD_list_new file

Type grep "celtic" CD_list_new and press Enter

Use a command to find out which lines in the my_list file contain the word "Foot".

Type grep Foot my_list and press Enter.

Use a command to replace the word "tree" with "plant" in the more_trees file and display the output to the screen

Type sed -n s/tree/plant/p more_trees and press Enter.

Use the sed command on the CD_list_new file to replace the words "LIGHT ROCK" with "EASY LISTENING" and the word "ALTERNATIVE" with "EXPERIMENTAL".

Type sed s/"LIGHT ROCK"/"EASY LISTENING"/ CD_list_new | cat > CD_list_new and press Enter. Type sed s/"ALTERNATIVE"/"EXPERIMENTAL"/ CD_list_new | cat > CD_list_new and press Enter

In the CD_list_new file, replace the word "misc" with "other," save the changes in the file CD_list_replace, and then compare the contents of the CD_list file with the CD_list_replace file to ensure your changes are implemented

Type sed s/misc/other/ CD_list_new > CD_list_replace and press Enter. Type comm CD_list CD_list_replace and press Enter. You might mention to students that another to do this is to type sed s/misc/other/ CD_list_new | cat > CD_list_replace.

Create a file called software with these fields: Project Number, using the same numbers shown in the project file (which you created earlier in this chapter) Software Code, using any three-digit number Software Description, such as Excel Then, write a small application joining records in the software file to matching records in the project file, and use the Awk program to print a report describing the software for each project you created earlier.

Type the following in the file: join -j1 1 -j2 1 -o 1.3 2.3 -t: software project > proj_report printf "\tProject Software Description\n" printf "=====================================\n" awk -F: '{ printf "%-30.30s %-12.12s\n", $2,$1 } ' proj_report

Use a command to make all letters uppercase in the CD_list_new file and save the output to a file called CD_list_uppercase.

Type tr '[a-z]' '[A-Z]' < CD_list_new > CD_list_uppercase and press Enter. Another solution is to type tr '[a-z]' '[A-Z]' < CD_list_new | cat > CD_list_uppercase and press Enter.

Use a command to find the duplicate lines (records) in the CD_list file.

Type uniq -d CD_list and press Enter.

Use the uniq command to remove the duplicate lines in the CD_list file, placing the corrected information in a file called CD_list_new

Type uniq CD_list CD_list_new and press Enter.

Determine the number of bytes in both the trees and more_trees files using a one-line command.

Type wc -c trees more_trees and press Enter.

How can you determine the number of lines and words in the /etc/termcap file?

Type wc -lw /etc/termcap and press Enter.

Find a command to compare the differences between three files and that creates output for individual lines.

Use the command diff3 file1 file2 file3

Create a file called trees, containing the following individual lines: Oak tree Pine tree Spruce tree Cottonwood Maple tree Use the vi editor to create a file called more_trees and copy in the contents of the trees file (if the first line is blank, delete it). Next, add the following trees at the end of the list. Redwood Willow tree Use a command to compare the trees and more_trees files and that outputs the differences in columns.

Use the vi editor to create the trees file. Use the vi editor with the :r option to import the trees file into the more_trees file and then add the new lines. Type comm trees more_trees and press Enter.

When you use the Awk printf capability, what does the dollar sign ($) represent?

a data field

In the command sed -f fixit notes > instructions, what is "fixit"?

a script file

When you design a record layout, you should do which of the following?(Choose all that apply.)

a. identify each field by data type , c. identify each field by name , and d. store only fields relevant to the record's purpose

What sed command option enables you to append new text to a file?

a\

The ____ command locates identical lines within two identically sorted files.

comm

compares sorted files and shows differences

comm

Your boss has two salary scale files, salary and salary1, and wants to compare their contents side by side to see if there are any differences in the files. Which of the following commands should he use?

comm salary salary1

selects columns (fields)

cut

compares and selects differences in two files

diff

A popular use of pr is to convert lowercase characters to uppercase characters.

false

You can use the < operator to redirect a command's output from the screen to a file.

false, >

What is the general format for using the pipe operator?

first_command | second command or first_command | second command | third_command (more commands can be piped)

You use the ____ command to search for a specified pattern in a file, such as a particular word or phrase.

grep

selects lines or rows

grep

You have just finished a 25-page paper that you have written using Emacs. The file containing the paper is called /assignments/data_sources. After your instructor has briefly looked at the paper, she recommends that you change all instances of the reference "data is" to "data are" before you submit it. Which of the following commands can you use to locate these references in the file for a quick assessment of how much you have to change?

grep "data is" /assignments/data_sources

Each time you list the files in your home directory, the output scrolls by so fast you can't read it. Which of the following enables you to view the output one screen at a time?

ls -l | more

The ____ redirects the output of one command to the input of another command.

pipe

formats and prints

pr

The ____ function within the awk command is used to format output.

printf

____ is NOT a selection command.

sed

edits data streams

sed

While in the Bash shell, you have written a simple script file and now want to execute the script. Which of the following commands enables you to run the script?

sh

sorts and merges multiple files

sort

translates and deletes character by character

tr

Your boss is trying to import the customers file into her spreadsheet program, but the data goes into the spreadsheet incorrectly. This is because the fields are separated by dashes (-) and the spreadsheet program requires the fields to be separated by colons (:). Which of the following commands can you use to convert the customers file?

tr "-" ":" < customers

Your boss is trying to delete the word "difficult" as it appears in a text file containing his speech about motivation. The name of the file is motivate. When he decides to use the tr command to delete this word, it instead deletes characters throughout the text. Which of the following commands is he likely to have used?

tr -d "difficult" < motivate

The pipe operator can connect several commands on the same command line.

true

You can use the less command with a directory to view its contents one screen at a time, such as less /sbin.

true

You can use the vi editor to create script files.

true

Because the data was formatted the same in two inventory files, you decided to combine their contents into one file. Now you want to determine if there are duplicate entries on consecutive lines in the new file. Which of the following commands enables you to find the duplicate entries?

uniq

The ____ command removes duplicate lines from a file.

uniq

____ is a selection command.

uniq

counts characters, words, or lines in a file

wc

You are creating a file to send over the Internet via a satellite connection that only allows you to send files under 250 KB. Which of the following commands enables you to determine the number of bytes in the file before you try to send it?

wc -c

You are interested in determining the number of words in your /assignments/data_sources file mentioned in Question 1. Which of the following commands should you use?

wc -w /assignments/data_sources

How can you link multiple files to manipulate the data in those files?

with a common or key field

Your friend is using the command comm entryfile, but is getting an error message. What is the problem?

you need to specify two files


Set pelajaran terkait

Genghis Khan and the Mongol Empire

View Set

BASIC OCCUPATIONAL HEALTH AND SAFETY

View Set

Old Testament chapter 22, Old Testament chapter 21

View Set

AP Econ Unit 4 Financial Markets and Monetary Policy

View Set

Nutrition Ch. 15- Hunger and the Future of Food

View Set

PrepU - Chapter 42: Management of Patients with Musculoskeletal Trauma

View Set