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.

Filter by
Sorted by
Tagged with
1 vote
4 answers
96 views

Remove last line of file by any user, owned by root

I have a file with permissions 666 so users can edit it with a different script. This works. I need to script to remove the last line of the file, however this is not working as using something like ...
Dave's user avatar
  • 572
1 vote
2 answers
108 views

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 ...
Pillager225's user avatar
2 votes
1 answer
98 views

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 ...
Edman's user avatar
  • 492
0 votes
1 answer
165 views

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 ...
Edman's user avatar
  • 492
3 votes
3 answers
814 views

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¯\|®...
Edman's user avatar
  • 492
2 votes
1 answer
447 views

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 ...
Edman's user avatar
  • 492
2 votes
1 answer
962 views

What are the main differences between the ed and the ex editor? [closed]

The ex editor is often touted as an enhancement and simplification of ed. I would like to know what specific enhancements and simplifications it offers. GNU ed, for example, offers extended regular ...
Edman's user avatar
  • 492
1 vote
1 answer
143 views

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 ...
Edman's user avatar
  • 492
1 vote
1 answer
27 views

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 ...
Edman's user avatar
  • 492
0 votes
1 answer
87 views

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.
Edman's user avatar
  • 492
0 votes
1 answer
51 views

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 ...
Edman's user avatar
  • 492
2 votes
2 answers
127 views

swap position of consecutive multiple lines in after pattern matching

I am trying to edit a big text file. What I am trying to achieve is swap lines from positions between 3 and 14 to positions between 16 and 27. I have extracted UPDATE statements from MySQL bin-logs ...
Avinash Pawar's user avatar
0 votes
1 answer
105 views

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's user avatar
  • 2,770
0 votes
1 answer
69 views

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's user avatar
  • 2,770
1 vote
1 answer
162 views

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 ...
Flux's user avatar
  • 2,770
1 vote
1 answer
208 views

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 ...
Flux's user avatar
  • 2,770
10 votes
9 answers
1k views

sed : have a range finishing with the last occurrence of a pattern (greedy range)

Take the following file : $ cat f1 stu vwx yza uvw xyz abc abc def ghi def ghi jkl ghi jkl mno jkl mno pqr mno pqr stu pqr stu vwx stu vwx yza To print all lines from the first one containing abc to ...
ChennyStar's user avatar
  • 1,497
0 votes
1 answer
172 views

Marking multiple lines in ed

I've opened ed and inserted the following text: This text Is a Test However, when I attempt to mark lines 1-3 using the following command: 1,3ki And print them with 'ip It only prints the last ...
GooseDeveloper's user avatar
2 votes
2 answers
112 views

Search with line numbers in GNU Ed

I have recently begun learning ed, however I've come to the point where I need to search for text. My first attempt was ed's / command, which will show occurrences, but doesn't include line numbers. ...
GooseDeveloper's user avatar
2 votes
1 answer
199 views

Adding a command to break long lines into shorter ones to an ed script

I frequently have long lines in my ed document which I would like to split into separate lines of max length. I found this command which achieves this: fold -s -w80 file Split very long lines I can ...
Edman's user avatar
  • 492
1 vote
1 answer
112 views

Changing the case of lines in ed

Can I employ the tr command to change the case of a line or range of lines while working in ed? Or is there another way?
Edman's user avatar
  • 492
0 votes
1 answer
72 views

How to obviate the problem of no spaces when joining lines in ed

In ed it is easy to join lines together. For example, 12,13j joins lines 12 and 13 -1,.j joins the line before to the current line However, ed does not add a space between the joined lines, and ...
Edman's user avatar
  • 492
1 vote
2 answers
161 views

Subexpression in ed for multiple substitutions

Let's say I have a piece of text that says: John went with Sally to the market where they bought fresh bread. There they met with Jim and dined together. Let's say that I wanted to write a regex to ...
Edman's user avatar
  • 492
0 votes
2 answers
190 views

Searching for X but not Y in ed

In the editor sam, one can search for and print out the string "ed" but not "red" with this command: ,x./*\n/ g/ed v/red p I was trying to find a way to do something similar in ed....
Edman's user avatar
  • 492
0 votes
1 answer
63 views

Is there a way to delete two non-juxtaposed duplicate lines in ed?

I was looking for a way to delete non-juxtaposed duplicate lines in ed such as, ed is a terminal editor sam is a bitmap editor emacs is a macro editor ed is a terminal editor I am hoping to produce: ...
Edman's user avatar
  • 492
0 votes
1 answer
123 views

Paste text into sam editor from an external application

I am running the editor sam as a standalone application on Linux. I am using this version: git clone https://github.com/9fans/plan9port plan9 So far I have not been able to figure out a way to paste ...
Edman's user avatar
  • 492
2 votes
1 answer
799 views

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?
Edman's user avatar
  • 492
2 votes
1 answer
378 views

Running an ed script from within ed

I have created a script file called "cleanup" which contains a series of regular expressions that clean up an ed file(s) of blank spaces, trailing white-space, blank lines etc. I run it as ...
Edman's user avatar
  • 492
1 vote
1 answer
275 views

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 ...
Edman's user avatar
  • 492
0 votes
1 answer
368 views

What is the difference between Gnu Ed and the version of Ed that ships with Unix?

I was wondering is there is any functional difference between Gnu Ed and the version of Ed which ships with BSD Unix systems? I am currently using Gnu Ed 1.17 on Debian 10 but discovered this page: ...
Edman's user avatar
  • 492
10 votes
2 answers
1k views

How would I replace two or more blank lines with a single blank line in Ed?

In Ed I can do a search to replace all blank lines as follows: g/^$/d This deletes all blank lines. But what if I wish to delete two or more blank lines and keep 1? For example: Line 1 Line 2 Line ...
Edman's user avatar
  • 492
2 votes
1 answer
89 views

Why does ed start at the last line?

Why does ed start at the last instead of first line of a file? Most of ed's behavior makes sense when you remember that it was for interacting with a printer, but not this. Since I believe it reads ...
John Baber-Lucero's user avatar
0 votes
1 answer
227 views

Replace "),(" with "),\n(" in Linux

Hy everybody. I have the following insert in a MySQL script file as an example that I obtained from mysqldump in Linux Ubuntu Server with no GUI. INSERT INTO `table` VALUES (AAAA, BBBB, CCCC),(DDDD, ...
Kekevalde22's user avatar
3 votes
1 answer
176 views

Why does ed support backreferences but not alternations in regular expressions?

I was looking into the history and development of regular expressions. I found the following timeline: 1956 - Kleene introduces regular expressions in his paper on nerve nets. 1964 - Brzozowsi ...
Buddha Buck's user avatar
0 votes
2 answers
109 views

Line editor ed saves some filenames in single quotes followed by one space

I'm following The Unix Programming Environment exercises and have encountered some weird issues. While going through the ed exercise, when you just start ed, type in the exercise, then do w poem It ...
Mark Scheck's user avatar
2 votes
1 answer
124 views

sdiff usage regaring merging changes in to an output file? How to come out of edit mode?

I tried sdiff file1 file2 -o file3 and everything seems to be going well. I could enter l or r to choose left or right side content in to the output file. But for a particular change, I had to edit ...
samshers's user avatar
  • 668
6 votes
1 answer
207 views

How do I move the last 3 lines of a pipeline to the top of the output with ed?

I have a small AWK script that summarizes the output of another program, and I am trying to print that summary before the command itself, but I cannot figure out a good way to do it. My naive first ...
Brent's user avatar
  • 63
0 votes
1 answer
294 views

Ed: is possible to substitute between one string and another one?

This command on ed editor /string.start/;/string.end/dp deleted all words (not the entire line, this happen using , instead of ;) between the string.start and string.end Is possible to replace/...
elbarna's user avatar
  • 12.4k
1 vote
1 answer
139 views

How do I see what files were changed by the "ed" command?

I'm trying to write a script that ensures all text files end with a newline character. When I run this command in a particular folder: find . -exec ed -s {} <<< w \; I get the following ...
Aaron Franke's user avatar
8 votes
8 answers
4k views

How to cut a file starting from the line in which a certain pattern occurs?

I have a gazillion files which need to be reduced in size. I found that most (not all) files have an end section which can be cut without losing information: Data 1 Data 2 something_unimportant_here ...
Ned64's user avatar
  • 8,596
1 vote
1 answer
275 views

How can I insert the contents of a shell command into my UNIX ed buffer?

I think I know how I can do this by writing to an external file, but I'm wondering if it's possible to directly insert the contents of a shell command into a UNIX ed buffer. I'm using GNU ed 1.15. ...
zacts's user avatar
  • 131
9 votes
1 answer
613 views

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?
Brennan Vincent's user avatar
0 votes
1 answer
112 views

ed(1) adds ^M to every line of my file

I am working on automating a WordPress install. While editing wp-config.php file, I need to replace 8 lines containing put your unique phrase here with Salt generated by WordPress.org servers. So, I ...
user avatar
3 votes
2 answers
1k views

ed(1) script with multiple search/replace

Working on a question for codegolf.se, trying to do a simple text replacement. Given a file coin.txt containing 1 word, either heads or tails I have an ed script flip.ed as follows: s/heads/1/n\ s/...
roblogic's user avatar
  • 217
6 votes
2 answers
1k views

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 ...
Jack Chen's user avatar
  • 159
2 votes
3 answers
1k views

How to reverse input order?

The following code provides a backwards output when inputted as first to last, so input is required to be in reverse. How can this be flipped/reversed? EDITED on 2019-05-23_07:52:04 (printf 'g?%s?m0\...
Anonymous's user avatar
  • 503
0 votes
2 answers
513 views

How to modify this `printf` code to reverse it's action?

Code below can, for example ... [anony@mous-pc ~]$ (printf 'g?%s?m0\n' 008 006 004 002 ; printf 'wq\n') | ed -s file.txt ... take all of numbers within ... [anony@mous-pc ~]$ cat some.txt 005 003 ...
Anonymous's user avatar
  • 503
1 vote
1 answer
187 views

How to move lines containing specific text to top of file in same order as code executed?

How to move lines containing specific text to top of file in same order as code executed? Here is the code I have: printf 'g?_001\|_002\|_003\|_004\|_005?m0\nwq\n' | ed -s target_file ( credit ...
Anonymous's user avatar
  • 503
1 vote
3 answers
387 views

Can I replace multiple characters in ed?

I have a text 'ab' whose content is composed of a,b letter. I want to change a to b, b to a at once by using s command in ed. But if I change them step by step, as you know, all the text will be ...
Godpoong's user avatar
-1 votes
3 answers
1k views

how to remove the empty/blank lines from files that appears as @ from vi

when I open file by vi as vi file Current partition replica assignment @ @ @ @ @ {"version":1,"partitions":[{"topic")] @ @ @ @ @ Proposed partition reassignment configuration but I try to delete ...
yael's user avatar
  • 12.8k