Questions tagged [ed]

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

Filter by
Sorted by
Tagged with
0 votes
0 answers
35 views

Problem pasting text into ed

If I paste text like this into ed: \c 65 \s1 text that looks like this \d Will be changed \q1 \v 1 Nominum textum latinum \q1\v 2 More text I get this: \c 65 \s1 text that looks like this \d Will ...
user avatar
  • 332
2 votes
2 answers
78 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 ...
user avatar
0 votes
1 answer
44 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?
user avatar
  • 1,832
0 votes
1 answer
42 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?
user avatar
  • 1,832
1 vote
1 answer
33 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 ...
user avatar
  • 1,832
1 vote
1 answer
33 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 ...
user avatar
  • 1,832
9 votes
10 answers
973 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 ...
user avatar
0 votes
1 answer
56 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 ...
user avatar
2 votes
2 answers
69 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. ...
user avatar
2 votes
1 answer
89 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 ...
user avatar
  • 332
1 vote
1 answer
56 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?
user avatar
  • 332
0 votes
1 answer
39 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 ...
user avatar
  • 332
1 vote
2 answers
76 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 ...
user avatar
  • 332
0 votes
2 answers
65 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....
user avatar
  • 332
0 votes
1 answer
44 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: ...
user avatar
  • 332
0 votes
1 answer
66 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 ...
user avatar
  • 332
1 vote
1 answer
153 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?
user avatar
  • 332
2 votes
1 answer
101 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 ...
user avatar
  • 332
1 vote
1 answer
104 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 ...
user avatar
  • 332
1 vote
1 answer
217 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: ...
user avatar
  • 332
9 votes
2 answers
449 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 ...
user avatar
  • 332
2 votes
1 answer
64 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 ...
user avatar
0 votes
1 answer
125 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, ...
user avatar
4 votes
1 answer
107 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 ...
user avatar
0 votes
2 answers
66 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 ...
user avatar
2 votes
1 answer
39 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 ...
user avatar
  • 554
6 votes
1 answer
160 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 ...
user avatar
  • 63
0 votes
1 answer
86 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/...
user avatar
  • 10.9k
1 vote
1 answer
80 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 ...
user avatar
8 votes
8 answers
3k 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 ...
user avatar
  • 7,487
1 vote
1 answer
65 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. ...
user avatar
  • 131
8 votes
1 answer
243 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?
user avatar
0 votes
1 answer
88 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
2 votes
2 answers
529 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/...
user avatar
  • 197
6 votes
2 answers
876 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 ...
user avatar
  • 159
2 votes
3 answers
638 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\...
user avatar
  • 459
0 votes
2 answers
291 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 ...
user avatar
  • 459
1 vote
1 answer
64 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 ...
user avatar
  • 459
1 vote
3 answers
190 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 ...
user avatar
0 votes
3 answers
833 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 ...
user avatar
  • 10.9k
1 vote
2 answers
2k views

Where is the editor choice kept in ranger?

On a fresh ranger install I tried to open neofetch config with ranger and selected ed to see what is it. I am glad Ctrl+D worked to exit the ed, but now ranger opens all files with it. Restarting ...
user avatar
4 votes
1 answer
130 views

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 ...
user avatar
  • 2,846
2 votes
1 answer
82 views

How shall I understand the different outputs by `-A` and by `-e` of diff3?

diffutils' manual says, in diff3 -A mine older yours The ‘--show-all’ (‘-A’) option acts like the ‘-e’ option, except that it brackets conflicts, and it outputs all changes from older to yours, not ...
user avatar
  • 89.8k
0 votes
1 answer
74 views

problem understaning /.*/

I have problem understanding /.*/ according to things written in books, this prints the entire line of the text. we know that. means any character, and * means zero or more occurrence of the preceding ...
user avatar
4 votes
3 answers
190 views

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?...
user avatar
  • 211
1 vote
2 answers
98 views

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 ...
user avatar
  • 3,715
7 votes
7 answers
7k views

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
user avatar
  • 173
7 votes
5 answers
7k views

Display only the penultimate (second last) row of a text [duplicate]

I have a poem with an unknown number of rows and I want to display only the penultimate one. What command should I use?
user avatar
  • 71
0 votes
1 answer
263 views

cut and paste in ed

Can someone tell me that how we do cut and paste in ed, for example for the following question? Write a script for ed which moves all lines starting with character # to the end of the input file?
user avatar
  • 41
1 vote
2 answers
557 views

why <<\END is used in ed [duplicate]

Using ed put character # to the beginning of lines 10 to 20 in file /etc/passwd. Solution is the following ed /etc/passwd <<\END 10,20s/^/#/ %p Q END my question is that what does << ...
user avatar
  • 41