I've recently used EDLIN from an 80s version of MS-DOS. After spending 5 minutes with the manual, I realized it was the best line editor I've ever used. ed is very similar, but it doesn't come with a nice manual. The info page is chaotic and doesn't start from the beginning. You can cover typical usage in 5 lines, but no, you have to read through 25 pages of stuff just to figure out a sensible command. I just use vim…
Batch editing files with ed
11–20 of 78 posts
Re: Batch editing files with ed
#12There is also ex, which is sort of cousin of ed, but also closer to nowdays more familiar vi(m).
$ ls -l /bin/ex
lrwxrwxrwx 1 root root 2 Oct 2 2017 /bin/ex -> vi
The original code for vi was written by Bill Joy in 1976, as the visual mode for a line editor called ex that Joy had written with Chuck Haley. Bill Joy's ex 1.1 was released as part of the first BSD Unix release in March 1978.[1](Bill Joy went on to become a co-founder of Sun Microsystems.)
"ex" stood for the extended version of ed.
Re: Batch editing files with ed
#13There is also ex, which is sort of cousin of ed, but also closer to nowdays more familiar vi(m).
Re: Batch editing files with ed
#14You could also just add the text after the matching line. A little simpler and more straight forward.
$ cat > /tmp/ed-script
/baz
a
- elephants
.
w
q
$ cat /tmp/2
foo:
- bar
- baz
- bananas
$ cat /tmp/ed-script | ed /tmp/2
33
- baz
47
$ cat /tmp/2
foo:
- bar
- baz
- elephants
- bananas
$·Re: Batch editing files with ed
#15 echo -e '/-baz\n+1\ni\n-elephant\n.\nw\nq\n'|ed foo
but ed requires a temp file in $TMPDIR to save changesfor speed, put $TMPDIR on memory file system
sed requires no temp file
1.sed:
/-baz/a\
-elephant
sed -f 1.sed foo|sed -a wfoo
works with all versions of sed, e.g., not all versions support "\n" in patterns nor so-called "edit-in-place" automatic temp file creation and removalRe: Batch editing files with ed
#16Nice article, good to hear ed is not dead. =) You could also just add the text after the matching line. A little simpler and more straight forward. $ cat > /tmp/ed-script /baz a - elephants . w q $ cat /tmp/2 foo: - bar - baz - bananas $ cat /tmp/ed-script | ed /tmp/2 33 - baz 47 $ cat /tmp/2 foo: - bar - baz - elephants - bananas $·
Re: Batch editing files with ed
#17sed s/baz/baz\\nelephants/
Re: Batch editing files with ed
#18sed s/baz/baz\\nelephants/
Re: Batch editing files with ed
#19Re: Batch editing files with ed
#20echo -e '/-baz\n+1\ni\n-elephant\n.\nw\nq\n'|ed foo but ed requires a temp file in $TMPDIR to save changes for speed, put $TMPDIR on memory file system sed requires no temp file 1.sed: /-baz/a\ -elephant sed -f 1.sed foo|sed -a wfoo works with all versions of sed, e.g., not all versions support "\n" in patterns nor so-called "edit-in-place" automatic temp file creation and removal