[ale] Another Large File/PERL/Awk/Sed question...

Ed Cashin ecashin at noserose.net
Wed Dec 2 08:21:35 EST 2009


On Tue, Dec 1, 2009 at 5:44 PM, Richard Bronosky <Richard at bronosky.com> wrote:
> Yeah, I was discussing the merits of hexedit and ed with a coworker
> for this specific edge case.

I like ed and use it often.  I'm curious what y'all were saying about ed
with regard to this particular case.

The following digression should not be misinterpreted as a slight
against non-purists.  :)

Personally, I like using always-there features.  As software ages, it
accumulates features that might not fit the original purpose of the
software, and those features are only available sometimes.  So if
I use sed in Inferno or Solaris, I have to check whether "-i" is there.
But ed is always there.

The creation of sed, the stream editor, was motivated by the desire
to perform ed-like operations on streams.  In-place editing was
already handled by ed.

For in-place removal of a trailing semicolon on the first line inside
a script, ed is convenient to use with a here document.  (Sorry if
somebody has already said this---the thread is getting long! ;)

ed myhugefile <<'EOF'
1s/;$//
w
q
EOF

With the printf command (which isn't available everywhere but does
behave consistently where it does appear), you can make one-liners
that use ed to edit in place.

printf '1s/;$//\nwq\n' | ed myhugefile

This is more portable but more verbose:

{ echo '1s/;$//'; echo wq; } | ed myhugefile

(I think "wq" does not work on all ed versions, but using two separate
commands works.)

-- 
  Ed Cashin <ecashin at noserose.net>
  http://noserose.net/e/
  http://www.coraid.com/


More information about the Ale mailing list