sed -e

Introduction

What the sed manual tells us

man sed

-e script, --expression=script add the script to the commands to be executed

In practice this means that you can perform several different actions. That is, some kind of script, and not just a single command.

For example

sed -e 's/string1/string2/g' -e 's/string4/string5/g'

It will first replace string1 with string2 and then string4 with string5

Example

Consider the file sites.txt

less sites.txt

AndreyOlegovich.ru IT
Aviasales Travel
Booking.com Hotels
Hotellook Hotels
TopBicycle.ru Bicycles
Velodrive Bicycles
HeiHei.ru Travel
Xiaomi Android
Samsung Android
Book24 Books
GeekBrains Education
Netology Education
TurboVPN VPN
Pluralsight Education
SovcomInsurance Insurance
Polis 812 Insurance
Polis 812 Insurance
Vivo Android
Reg.ru Hosting
OLDI Laptops
…

Suppose we need to make a new list of sites new.txt only write Bikes instead of Bicycles, and the insurance sites are not needed at all

The flag lets you run two commands at once -e

sed -e 's/Bicycles/Bikes/' -e '/Insurance/d' sites.txt > new.txt
cat new.txt

AndreyOlegovich.ru IT
Aviasales Travel
Booking.com Hotels
Hotellook Hotels
TopBicycle.ru Bikes
Velodrive Bikes
HeiHei.ru Travel
Xiaomi Android
Samsung Android
Book24 Books
GeekBrains Education
Netology Education
TurboVPN VPN
Pluralsight Education
Vivo Android
Reg.ru Hosting
OLDI Laptops
…

Delete everything between the brackets

Including the brackets themselves, by running

sed -i -e 's/\[[^][]*\]//g' sample.txt

Article author: Andrei Olegovich