http://en.wikipedia.org/wiki/Concatenative_programming_langu...
- Awk: That thing I use when I need to grep for something over more than one line and/or do some basic transformations.
- Sed: That thing with the painful syntax for doing ridiculously complicated regex substitutions.
With that said, I find sed much more difficult to use than awk and generally try to avoid it if I can. I'm even prone to just opening the file in vim and executing the replace command through that rather than using sed.
I would use awk when there are a handful or more of potential transformations: Does the current line match any of these multiple patterns? Do the action that's defined for each of the patterns, then move on to the next line.
If I need to do multiple transformations, and still want to use sed, I find it easiest to create a chain of single sed transformations, piped together. Somewhere in that area a shift to awk (or python) becomes justified.
Sed scripts are a quick way to automate simple edits to large files.
grep foo somefile | sed 's|/path/to/some/file|/new/path|g'
Lot nicer than all those picket fences \/\/\/
sub(r, t, s)
substitutes t for the first occurrence of the regular expression r in the string s. If s is
not given, $0 is used.
gsub same as sub except that all occurrences of the regular expression are replaced; sub and gsub
return the number of replacements.