Multiple edits – the e command

If we need to perform multiple editing with the same command, then we can use the -e command. Each edit command should be separated by the -e command. sed will apply each editing command separated by -e on the pattern space before loading the next line in the pattern space:

    $ cat shopping.txt
  

The output is as follows:

    Product     Quantity  Unit_Price  Total_Cost
    Apple       2          3            6
    Orange            2          .8           1.6
    Papaya      2          1.5          3
    Chicken     3          5            15
    Cashew            1          10           10
  

This is an example:

    sed -e '5d' -e 's/Cashew/Almonds/' shopping.txt
  

The output is as follows:

    Product     Quantity  Unit_Price  Total_Cost
    Apple       2         3           6
    Orange            2         .8          1.6
    Papaya            2         1.5         3
    Almonds     1         10          10
  

Initially, the command for deleting the fifth line is called, then, the next substitution ...

Get Learning Linux Shell Scripting - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.