ed

Why can't I print this regex range with ed(1)?

Why can't I print this regex range with ed(1)? I’m totally mystified why I can’t print this range with ed when there are two ranges—see file2.tf file—; but I can print when there is only one range—see file1.tf file—and I can print with the gsed (GNU sed on macOS) command; but I can’t print with …

Total answers: 1

POSIX way to add content around a line in a file

POSIX way to add content around a line in a file I’m looking for a way to edit files with a script that will provide an alternate definition for a variable in C and this redefinition is controlled by a compiler D-flag using a POSIX application that I write a script for. So for example, …

Total answers: 2

How to increase the size of the .ed_history file

How to increase the size of the .ed_history file I am running GNU ed 1.18 on Fedora Linux 36. I run ed with rlwrap also installed which gives me access to my command history. My .ed_history file appears to have a size limit of 300 lines. I would like to increase that limit, perhaps to …

Total answers: 1

Inserting the line to be changed in ed

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 change.) …

Total answers: 1

Replacing strange characters in a sed command

Replacing strange characters in a sed command I want to create a sed command that will remove all of these strange characters from a given document: sed -n ‘s/|®MD-IT¯|®MD+BO¯|®MDNM¯®LL.8LI,0LI¯|®LL0LI,0LI¯|®MD+IT¯|®LL.8LI,0LI¯®MDIT¯|®MDNM¯®FL¯®LL.8LI,0LI¯|®FL¯®MD-BO¯|®FL¯®MD-BO¯|®MD-BO¯|¯®OF1IN,1IN¯®FC¯®LL1LI,0LI¯||®SF1,1¯|®FM1FT=0LI,LR=1;|®MDSU¯®FN1¯|®MDNM¯¯|®IV-RTF|……………………………………………………….|¯®BF0¯|®FS1|————————————-|¯®FW1||//gp’ These codes were all created in another application Nota Bene and I have many files with such codes that I would like to convert to plain …

Total answers: 3

ed does not join lines with ASCII text, with CRLF, LF line terminators

ed does not join lines with ASCII text, with CRLF, LF line terminators I am currently running Gnu ed version 1.18 in the Debian WSL on Windows. If I edit a file with the following encoding: ASCII text, with CRLF, LF line terminators or ASCII text, with CRLF, then ed does not properly join lines …

Total answers: 1

Ed bookmarks disappear after a global replacement

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 bookmark and then perform …

Total answers: 1

Typing unicode characters into ed

Typing unicode characters into ed I wondered if it was possible to type Unicode characters like an em_dash and curly quotes into ed. I am completing a project that requires these special characters in the document. Asked By: Edman || Source When in user input mode, the ed editor takes the input from the user …

Total answers: 1

Substituting the second occurrence of a word/phrase in ed

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 having …

Total answers: 1

Showing line numbers by default in ed

Showing line numbers by default in ed In the ex editor, one can show line numbers by default by adding this line to a .exrc file: set number Is there a way to have ed start with line numbers showing by default, when lines are invoked? Asked By: Edman || Source No, there isn’t. You …

Total answers: 1

Insert text N lines before the last line

Insert text N lines before the last line I want to insert a new line in two lines before the last line. So if my original file is: 1 2 3 4 5 The result should be 1 2 3 New line 4 5 Asked By: Gautam || Source Using ed: $ printf ‘$-1inNew linen.n,pn’ …

Total answers: 7

In ed (line editor), how to create a new file for editing?

In ed (line editor), how to create a new file for editing? I’m not able to open a new-file for editing in the standard line-editor, ed. I’m able to open an existing file though. The user guide I’m referring says, ed should return ‘?barney’ i.e ?[new_file_name]; however in my case it searches for existing files. …

Total answers: 2

What text editor was used by Thompson and Ritchie in the writing of Unix?

What text editor was used by Thompson and Ritchie in the writing of Unix? I think that it’s probably qed, but I can’t find any sources to confirm or deny this. Also, ed has existed for the entire duration of Unix, and sam was written in the early 1980s. Is it known what most people …

Total answers: 1

Why can't ed be exited with C-c?

Why can't ed be exited with C-c? The program ed, a minimal text editor, cannot be exited by sending it an interrupt through using Ctrl–C, instead printing the error message “?” to the console. Why doesn’t ed just exit when it receives the interrupt? Surely there’s no reason why a cryptic error message is more …

Total answers: 4

How to remove multiple newlines at EOF?

How to remove multiple newlines at EOF? I have files that end in one or more newlines and should end in only one newline. How can I do that with Bash/Unix/GNU tools? Example bad file: 1n n 2n n n 3n n n n Example corrected file: 1n n 2n n n 3n In other …

Total answers: 10

How to write a literal dot in ed?

How to write a literal dot in ed? What would be the right way to write a line containing only . to a file in ed? The only way I came up with is something like this: a . s/^$/./ Asked By: Staven || Source A bit round about, but use shell redirection: r !echo …

Total answers: 2

Is the `ed` editor useful for any purpose besides emergencies and batch editing?

Is the `ed` editor useful for any purpose besides emergencies and batch editing? I’m wondering if the ed editor is useful any longer for interactive editing. I know that the diff command can produce patches as ed scripts and that ed is a last resort when the baud rate is super slow. But are there …

Total answers: 5