I understand sed
will
- Applies all instructions on line 1, then line 2...
- Previous instructions may change the pattern space so the next instruction will operate on that modified pattern space (instead of the original text)
The example is:
sample.txt file
pig cow
Command
sed -e 's/pig/cow/; s/cow/horse/;' sample.txt
Expected Output
horse horse
Real Output
horse cow
The reason for my expected output is:
- First instruction substituted pig with cow in the pattern space
- Second instruction substituted 2 pigs with 2 horses in the pattern space
g
flag to apply the instruction on the whole line. If you could post this as an answer, I would gladly mark it as the solution. – Tran Triet Oct 10 '18 at 06:29