Questions tagged [ed]

For questions about the editor ed, a scriptable line-oriented text editor, originally written by Ken Thompson for the Multics and Unix operating systems. Use this tag for questions about ed itself or questions about issues arising from using the ed editor.

The ed utility is a line-oriented text editor that uses separate command and input modes. In command mode, the input characters are interpreted as commands, and in input mode, they are interpreted as text.

External reference

ed specification (The Open Group Base Specifications Issue 7, 2018 edition)

81 questions
9
votes
1 answer

How can I insert a lone dot on a line using ed's "insert" command?

How may I insert a lone dot on a line with the ed editor? Normally, a dot on a line by itself ends the insertion; can it somehow be escaped?
6
votes
2 answers

ed command: Delete from line 1 until the first blank line

I came across this code from a textbook; the book only says that 1,/^[ ]*$/d means “Delete from line 1 until the first blank line.” What does each character specifically mean? ed $1 << EOF 1,/^[ ]*$/d w q EOF
Jack Chen
  • 169
4
votes
1 answer

ed print the next n lines as succinctly as possible

I'm trying to understand the ed DSL a little bit better because versions of it show up in other tools (e.g. sed, vim). Using ed it is possible to print the next 4 lines using .,+4n where .,+4 is an explicit range starting at the current line and…
Greg Nisbet
  • 3,076
4
votes
3 answers

ed invalid address macOS

/Delete/,/endif/p ? invalid address /Delere/,/endif/p ? no match Does it mean it understands latin only? /Dele/,/endif/p ? invalid address /Del/,/endif/p ? invalid address No, what am I doing wrong? I'm typing out all letters without any…
Adam
  • 211
3
votes
3 answers

How does one indent code blocks in `ed`?

I like using ed for small edits. Currently I just press the spacebar manually to indent blocks of code in ed. Is this how the authors of UNIX indented their code in ed? Or is there some shortcut they used I don't know about?
dan
  • 4,077
  • 5
  • 27
  • 34
1
vote
1 answer

Deleting specific line numbers in ed in a single command

In ed one can delete a line number by typing its address followed by the delete command, as in 1d. To delete a range of lines, one uses the comma, as in 1,4d. One can also delete lines with specific content as in g/Ted/d. Is there a way to specify…
Edman
  • 492
1
vote
1 answer

Ed bookmarks disappear after a global replacement

If I make a bookmark in ed for an address by invoking k plus any other letter, I can return to that address later by invoking '+letter. I frequently make these bookmarks, especially when navigating a long document. However, if I create such a…
Edman
  • 492
1
vote
1 answer

How to enable help mode by default in ed

After starting ed, help mode can be enabled using the H command. Is there a way to enable help mode by default, so that I do not have to type H every time I use ed?
Flux
  • 2,938
1
vote
1 answer

How to cancel the current input in ed

In GNU ed, is there a way to cancel the current input? For example: $ ed myfile.txt 1234 a Wrong speling. Bad sentance. At this point, I want to cancel the input. I no longer want to insert the two lines that I have typed. Is it possible? I…
Flux
  • 2,938
1
vote
1 answer

How do I move to a line in ed without printing the line?

In GNU ed, how do I move to a line without printing it? If I want to move to line 123, I would input 123 Enter, but that would also print the contents of the line. Is there a way to not print when moving to a line?
Flux
  • 2,938
1
vote
1 answer

Is there a command in ed that repeats the last command?

Is there a command in ed that repeats the last command? I know that one can repeat the last search (with //) but a command to repeat and/or edit the last command without having to retype it would be helpful.
Edman
  • 492
1
vote
2 answers

Is it possible to filter a set of lines through an external command in ed?

In ed, one can retrieve the output of a command into the current buffer by using r !COMMAND. One can also write a set of lines to the input of a command by using 1,3w !COMMAND. However, I cannot determine how to do both simultaneously. r 1,3w…
merlin2011
  • 3,925
0
votes
1 answer

Inserting the line to be changed in ed

In ed there is the useful c command which allows one to make changes to a specific line. (Using rlwrap as well allows for easier changes, once a line has already been changed, because one can use the up and down arrows to introduce a previous…
Edman
  • 492
0
votes
1 answer

Substituting the second occurrence of a word/phrase in ed

What would the syntax be for replacing only the second/third occurrence of a word/phrase in ed? He wanted to buy groceries from the shop, but preferred not having to go into the shop. >> He wanted to buy groceries from the shop, but preferred not…
Edman
  • 492
0
votes
1 answer

How to scroll backward in ed

BSD ed and GNU ed have the z command for scrolling. However, repeatedly using the z command only seems to scroll forward. Is there something similar to z that can scroll backward instead of forward?
Flux
  • 2,938
1
2