what does dash e(-e) mean in sed commands?

sed

Solution

The sed -e commands are combined to create a single sed script. The following yields the same results (notice that -e is implied):

sed '
    s/1/ONE/
    s/2/TWO/
    /3/q
    s/ONE/THREE/
' input.txt

Or as a one liner:

sed 's/1/ONE/; s/2/TWO/; /3/q; s/ONE/THREE/' input.txt

Problem

I am new to sed, and always execute one command on an input file, recently I try to use `"-e"` to work on multiple commands, but I cannot figure out how it really work, the default print is quite annoying, so I cannot figure out in which order the commands are executed. ``` sed -e 'command 1' -e 'command 2' input.txt ``` content of input.txt: ``` line1 line2 line3 ``` Question 1: What is the processing flow? is it ``` command1 processes line1 and then command2 processes new-line1(processed by cmd1) command1 processes line2 and then command2 processes new-line2(processed by cmd1) command1 processes line3 and then command2 processes new-line3(processed by cmd1) ``` or ``` command1 processes line1 command1 processes line2 command1 processes line3 command2 processes new-line1(already processed by cmd1) command2 processes new-line2(already processed by cmd1) command2 processes new-line3(already processed by cmd1) ``` Question 2: As i mentioned, the default print is quite annoying, should I use -n in front of the first -e or in front of both -e? Thanks in advance. Edit(It seems the working flow is the first assumption): ``` input.txt 1 2 3 sed -e '{s/1/ONE/;s/2/TWO/;/3/q}' -e '{s/ONE/THREE/}' numbers.txt THREE TWO 3 ``` I tried the above command, and it seems the working flow is command1 processes line1, and then command2 processes new-line1(cmd1 processed it), and then cmd1 processes next line

Original source