sed command examples Flashcards

1
Q

Sed editing commands

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

Sed options

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

find all the lines containing pattern “erors”

A

sandy ~> sed ‘/erors/p’ example

This is the first line of an example text.

It is a text with erors. It is a text with erors.

Lots of erors. Lots of erors.

So much erors, all these erors are making me sick.

So much erors, all these erors are making me sick.

This is a line not containing any errors.

This is the last line.

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

only print those lines matching our pattern

A

sandy ~> sed -n ‘/erors/p’ example

It is a text with erors.

Lots of erors.

So much erors, all these erors are making me sick.

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

see the lines not containing the search string

A

sandy ~> sed ‘/erors/d’ example

This is the first line of an example text.

This is a line not containing any errors.

This is the last line.

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

Matching lines starting with one pattern and ending in a second pattern

A

sandy ~> sed -n ‘/^This.*errors.$/p’ example

This is a line not containing any errors.

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

take out the lines containing the errors

A

sandy ~> sed ‘2,4d’ example

This is the first line of an example text.

This is a line not containing any errors.

This is the last line.

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

print the file starting from a certain line until the end of the file

A

sandy ~> sed ‘3,$d’ example

This is the first line of an example text.

It is a text with erors.

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

search and replace the errors instead of only (de)selecting the lines containing the search string.

A

sandy ~> sed ‘s/erors/errors/’ example

This is the first line of an example text.

It is a text with errors. Lots of errors.

So much errors, all these erors are making me sick.

This is a line not containing any errors.

This is the last line.

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

Use the g command to indicate to sed that it should examine the entire line instead of stopping at the first occurrence of your string

A

sandy ~> sed ‘s/erors/errors/g’ example

This is the first line of an example text.

It is a text with errors.

Lots of errors.

So much errors, all these errors are making me sick.

This is a line not containing any errors.

This is the last line.

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

insert a string at the beginning of each line of a file

A

sandy ~> sed ‘s/^/> /’ example

> This is the first line of an example text.

> It is a text with erors.

> Lots of erors.

> So much erors, all these erors are making me sick.

> This is a line not containing any errors.

> This is the last line.

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

Insert some string at the end of each line

A

sandy ~> sed ‘s/$/EOL/’ example

This is the first line of an example text.EOL

It is a text with erors.EOL

Lots of erors.EOL

So much erors, all these erors are making me sick.EOL

This is a line not containing any errors.EOL

This is the last line.EOL

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

Multiple find and replace commands are separated with individual -e options

A

sandy ~> sed -e ‘s/erors/errors/g’ -e ‘s/last/final/g’ example

This is the first line of an example text.

It is a text with errors.

Lots of errors.

So much errors, all these errors are making me sick.

This is a line not containing any errors.

This is the final line.

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