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
3
votes
1answer
42 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 ...
1
vote
1answer
83 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, ...
1
vote
0answers
50 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 ...
0
votes
2answers
46 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 ...
2
votes
1answer
26 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 ...
6
votes
1answer
140 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 ...
0
votes
1answer
39 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/...
1
vote
1answer
47 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 ...
7
votes
7answers
2k 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 ...
1
vote
1answer
44 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. ...
5
votes
1answer
115 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?
0
votes
1answer
67 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 ...
1
vote
2answers
291 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/...
6
votes
2answers
604 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 ...
2
votes
3answers
483 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\...
0
votes
2answers
173 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 ...
1
vote
1answer
48 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 ...
1
vote
3answers
140 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 ...
0
votes
3answers
685 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 ...
1
vote
2answers
1k 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 ...
4
votes
1answer
105 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 ...
2
votes
1answer
70 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 ...
0
votes
1answer
71 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 ...
4
votes
3answers
159 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?...
1
vote
2answers
72 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 ...
7
votes
7answers
5k 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
7
votes
5answers
5k 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?
0
votes
1answer
199 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?
1
vote
2answers
341 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 << ...
0
votes
1answer
50 views

How to use 'itextESC' when using ex as a text editor in command line?

I like using the traditional ex editor for simple command line operations, to re-arrange text within files. For example for a simple moving lines across in a file I would use something like foo bar ...
2
votes
4answers
2k views

Swap lines in text file only where containing strings using sed or ed? [closed]

I need to swap these lines, only where the matching strings are in both lines: before: REF*CE*------------------------- REF*1W*------------------------- after: REF*1W*------------------------- REF*...
0
votes
1answer
622 views

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 ?[...
11
votes
1answer
2k views

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 ...
4
votes
1answer
355 views

Ed script only works if typed slowly

In this context I've encountered a situation where ed file < script would print ? and exit with error 2, while typing or pasting the commands from script one at a time worked fine. Even having a ...
-1
votes
3answers
187 views

How to catch with RegExp first word with different first symbol in it using ed text editor

I have shell command: printf '/^PermitRootLogin/\nc\nPermitRootLogin no\n.\nw\nq\n' | ed -s /etc/ssh/sshd_config And I need catch #PermitRootLogin like PermitRootLogin but not commented paragrath ...
11
votes
8answers
9k views

sed in-place line deletion on full filesystem?

Due to an application bug as yet undiagnosed, I have several hundred servers with a full disk. There is one file that has been filled up with duplicate lines—not a log file, but a user environment ...
0
votes
1answer
943 views

How to switch from input mode into command mode in ed ?

As far as I know, ed starts in command mode. Once I input i,a or c ed changes into input mode. So far it worked. Now I read that in order to switch from input mode into command mode one has to input ",...
6
votes
3answers
494 views

Echoing stdin when running an ed(1) script

Given the following ed script, $ cat helloworld a hello world . ,n ,s,o,O,g ,n Q I would like to obtain somehow the interactive output $ ed a hello world . ,n 1 hello 2 world ,s,o,O,g ,n 1 ...
2
votes
2answers
4k views

How can I replace ^I into tab spaces in vim editor for .java file?

When I open my .java file in vim, I could see a couple of lines prefixed with one / more ^I characters. It looks like tabs in Eclipse that has got converted into ^I. I would like to replace a single ^...
22
votes
4answers
17k views

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 ...
4
votes
3answers
420 views

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 ...
8
votes
2answers
2k views

Regex `/pattern/g` and ed `:g/pattern/`: which came first, and why `g`?

The g option (e.g. s/pattern/replacement/g) for many tools that use regex-style pattern matching and the :g command in ed, ex, vi, and vim have pretty similar usage and meaning: match the given regex "...
0
votes
1answer
75 views

Getting a delimiter issue while executing the script

I am creating a test.sh file and i am running it as ./test.sh: string="hello" ed << EOF e any_file 1i ${string} EOF can anybody help me what it does? I am getting some delimiter issue. Can ...
28
votes
10answers
20k views

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: 1\n \n 2\n \n \n 3\n \n \n \n Example corrected file: ...
2
votes
2answers
556 views

Removing consecutive newlines with ed

Input file: 1 line1\ 2 line2\ 3 line3\ 4 \ 5 line4\ 6 \ 7 \ 8 line5\ Desired output: 1 line1 2 line2 3 line3 4 5 line4 6 7 line5 Is it possible with POSIX ed? Removing the trailing backslashes is ...
8
votes
2answers
604 views

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/^$/./