sed vs awk

2025年2月26日

For anything other than simple substitutions on a single line you should be using awk, not sed. Hold spaces, pattern spaces, and 95% of the sed language constructs were invented before awk when there was no better alternative. They became obsolete as soon as awk was invented in the mid-1970s and are only kept alive today by people who enjoy solving problems using seds arcane syntax rather than doing it simply and cearly in awk. If you are using more than s, g, and p (with -n) in sed then you are almost certainly using the wrong tool.

Ed Morton on Jul 7, 2013

sed always divides the input by the new line character. The option –null-data or –zero-terminated stops splitting lines, and thus the unit of matching becomes the whole input rather than lines. There is no way to change the line separator.