Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [ed]

A scriptable line-oriented text editor, originally written by Ken Thompson for the Unix operating system.

6
votes
2answers
94 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
152 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
71 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
38 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
30 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
117 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
227 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
76 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
48 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
66 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
97 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
42 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
1k 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
2k 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
99 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
85 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
35 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
540 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
375 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 ?[...
9
votes
1answer
746 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 ...
3
votes
1answer
183 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
134 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
6k 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
622 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 ",...
5
votes
3answers
399 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
2k 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 ^...
18
votes
4answers
12k 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
189 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 ...
7
votes
2answers
1k 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
69 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 ...
24
votes
10answers
14k 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
475 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
461 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/^$/./