The ed editor is a very ancient and primitive editor. This was all there was back in neolithic times, but now its simplicity is sometimes useful when performing operations on files from scripts when the load times of Vim and other modern editors are too long.
Deleting A Line In Place
For me this is the most common modern simple task for the ed editor:
printf "%s\n" "10d" "w" "q" | ed -s thefile
The printf
sends a sequence of commands followed by newlines to the ed
program which acts on thefile
. In this case line 10 gets deleted, the
new file (missing its former line 10) gets written (w) and then the
program is quit (q). The -s
, for silent, makes ed suppress its
cryptic and terse output which is definitely not needed for this
script.
Note
|
Modern sed implementations can often do
in-place editing with -i flag. |