Search code examples
sedawkturing-complete

What can awk do that sed can't?


I used sed for a batch ptovess where I could not do it with awk. Vould awk have done it? Or is it more a matter of choice and call awk and sed equivalent for the usage. They both do the common search replace similar with i/o. Is there a good example what can't be done with one that the other can?


Solution

  • One main difference is that an awk program can maintain state and can operate using multiple passes over the same data. A sed invocation is necessarily stateless single-pass because sed (Stream EDitor) is inherently stream-oriented. The advantage, though, is that this makes sed simpler and more appropriate for using in pipe chains.