[H-GEN] Simple Linux editors

Greg Black gjb at gbch.net
Sun Apr 7 22:59:38 EDT 2002


[ Humbug *General* list - semi-serious discussions about Humbug and     ]
[ Unix-related topics. Posts from non-subscribed addresses will vanish. ]

Robert Brockway wrote:

| On Sun, 7 Apr 2002, Greg Black wrote:
| 
| > The editor of choice for Unix sysadmin work is of course ed.
| 
| Now now Greg :)  While I'm sure you and I have both fixed systems with
| ed[1] I'm sure you'd agree that vi is more popular for the task :)

Perhaps, but popularity is not a reason for making a choice.  If
it was, I'd be using Windows and eating at Maccas every day.

To put this into perspective, I think it's worth making the
point that ed is often the only tool available for emergency
editing and that no competent sys admin (or programmer) will be
troubled at the thought of using it.

I have always made it a rule not to employ either sys admins or
programmers who could not handle basic ed tasks without needing
the manual.  For that reason, I use ed every day -- to ensure my
skills don't rust but also because it's often the ideal tool.

Of course, I also use vi a few times a week to keep my hand in,
but skills with vi are of much less concern to me.

| [1] actually had to fix a system with echo & cat once :)  Don't ask :)

I use cat often to create files, although it's a little limited
as an editor :-)

| > It's small, fast, easy to use, allows a bit more flexibility
| > than cat, and just works.
| 
| sed.
| sed for ever
| Using sed lets me sleep better at night.

I know you know this, but for the benefit of the newbies here, I
should point out that there are lots of things that are easy
with ed that sed can't do easily -- both ed and sed have their
place.  Of course, the principle reason for learning ed is also
one of the principle reasons why sed is not a useful substitute:
on a traditional Unix system, ed is in /bin while vi and sed are
in /usr/bin -- this means that they may not be available on a
system that is toast for some reason, and it's on those systems
that we need to be able to use the tools that are sure to be at
hand.

To clarify the kinds of operations that I expect people to be
able to handle with ed, here are some examples -- note that none
of these tasks involves the tricky or arcane corners of ed.

   1. List the entire file (single character command).

   2. List the entire file with line numbers (2 character
      command).

   3. List a range of lines with or without line numbers.

   4. Replace all instances of `foo' with `bar', printing the
      affected lines with their line numbers.

   5. Replace all instances of `foo' or `bar' with `foobar',
      printing the affected lines with their line numbers.

   6. Same as (5), but over a range of lines.

   7. Replace all instances of `foo' with `bar' in lines that
      contain `baz' at least twice.

   8. Replace the entire contents of a line or range of lines
      with new text.

   9. Delete a range of lines.

  10. Copy a range of lines to a different location.

  11. Same as (10), but move the lines.

  12. Split a line and join a pair of lines.

  13. Undo the last change.

  14. Save the current file.

  15. Save part or all of the file to another file name.

  16. Read in another file to a specified place in the current
      file.

Of course, there's a lot more that can be done with ed, as a
read of the FM will reveal to those who don't yet know this very
useful tool.

Note: I'm not trying to start an editor war here.  I don't write
code with ed except when I need to or when I'm making a small
change to something in a hurry; and I certainly don't write
documentation with ed or suggest to my customers or family that
they should be using ed.  But, for sys admins and programmers,
it's an indispensable tool.  And you should make friends with it
so that you can use it when the need arises.  The reason for
learning to use it unassisted is that you'll often need it at
times when nice things like on-line documentation are not going
to be available.

And it's also worth noting that knowing ed is part of knowing
Unix and that the Unix grep command takes its name from ed's
syntax to do the same thing that grep does.

Greg

--
* This is list (humbug) general handled by majordomo at lists.humbug.org.au .
* Postings to this list are only accepted from subscribed addresses of
* lists 'general' or 'general-post'.  See http://www.humbug.org.au/



More information about the General mailing list