View Single Post
Old 8th November 2010
drl's Avatar
drl drl is offline
Port Guard
Join Date: May 2008
Posts: 19


My take on this is that the in-place options on most utilities are something of a misnomer. The data is written to a scratch file, then copied back onto the original -- one does not get something for nothing. This is true of "-i" on GNU sed, as well as the interactive editors ed/ex. So that the in-place description refers to the result rather than the method.

To be sure, in place options are useful devices for convenience, but one could as easily use sed/awk with a utility like sponge: , part of moreutils, source at , or write a scratch file oneself.

There are times when I use the interactive editors ex/ed in scripting mode, but it's far more often as a demonstration that it can be done, rather than to do it in practice.

The operation of ed/ex compared to sed/awk is different in the sense that -- at least with sed -- most often a line is read in, operated upon, and written out. The ed/ex editors will read in the entire file (possibly making an index of the locations of the lines on a scratch file), so that the memory demands can be significant.

In most of the situations I have seen, sed/awk is far more often used than is ed/ex for scripting tasks. However, when the file is small enough and certain requirements are present -- such as addressing a line before a line that matches a pattern -- then ed/ex can be quite useful.

There are adherents of sed on, but I think the flexibility and speed of GNU awk makes it a tool that one finds oneself reaching for more often than for sed. For the everyday tasks of dealing with fields of data, I have not found a more useful utility than awk.

For mimicking the data-tool-connecting philosophy of *nix, I have found perl better, in that it deals with command-line options better than does awk. For example, the module Getopt::Euclid automatically will produce documentation and an option parser from one set of documentation sequences (POD mark-up). Externally, then, one could ask for
perl-script-name --man
to get man-style documentation, and the code will also parse command-line options.

Best wishes ... cheers, drl

( Edit 1: typo )

Last edited by drl; 8th November 2010 at 10:46 AM.
Reply With Quote