multiple sed expressions

There are several ways to run several sed commands at once

Curly braces { }

sed '{
/^pool 0/ i 0.fi.pool.ntp.org
/^pool\s[0-9]\.ubuntu/ d
} ' /etc/ntp.conf

After the opening curly brace you can press Enter and continue entering commands

You can apply several commands to one file

.sed file

A set of commands can be saved as a file.

Let us look at ntp.sed

cat ntp.sed

/^pool 0/ i 0.fi.pool.ntp.org
/^pool\s[0-9]\.ubuntu/ d

Now it can be applied to any file

sed -f ntp.sed /etc/ntp.conf

Where -f means file

man sed

-f script-file, --file=script-file add the contents of script-file to the commands to be executed

Another way to run several commands at once is to use -e

Read about it in the next article

«--expression=script»

Article author: Andrei Olegovich