15 sed stream editor Flashcards

1
Q

sed scripts can be provided on the command line

A

sed [-e] ‘command’ files

All commands are applied in sequence to each line

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

sed scripts can be provided in a separate file

A

sed -f scriptfile files

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

General form of a sed command:

A

[address[,address]][!]command[arguments]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Addresses

A

Addresses can be line numbers or regular expressions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Last line

A

Last line is “$”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Line range

A

One address selects a line, two addresses a line range (specifying start and end line).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Optionally print

A

After this, the line is printed, unless option -n is used, in which case only the p command will print a line.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Negate address matches

A

The ! negates address match. {. . . } can group commands per address.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Regex enclosed in

A

Regular expressions enclosed in /. . . /. Some regular expression meta characters:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

matches any character (except new-line)

A

“.”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

matches the preceding item zero or more times

A

“*”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

matches the preceding item one or more times

A

“+”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

matches the preceding item optionally (0–1 times)

A

“?”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

matches start of line

A

“^”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

matches end of line

A

“$”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

matches one of listed characters

use in character list “^” to negate and “-” for ranges

A

“[. . . ]”

17
Q

grouping, “{n,m}” match n, . . . , m times

A

“(. . . )”

18
Q

escape following meta character

A

“\”

19
Q

Substitute all occurrences of “Windows” with “Linux” (command: s = substitute, option: g = “global” = all occurrences in line):

A

sed ‘s/Windows/Linux/g’

[used within a pipeline]

20
Q

Delete all lines that do not end with “OK” (command: d = delete):

A

sed ‘/OK$/!d’

21
Q

Print only lines between those starting with BEGIN and END, inclusive:

A

sed -n ‘/^BEGIN/,/^END/p’

22
Q

Substitute in lines 40–60 the first word starting with a capital letter with “X”:

A

sed ‘40,60s/[A-Z][a-zA-Z]*/X/’