Questions tagged [ed]

ed is a line-oriented text editor for Unix. Use this tag for questions related to ed scripting; questions about interactive usage are considered off-topic.

ed was created in 1969 by Ken Thompson as a simplified successor to the QED editor and was part of the first version of Unix. It is still part of the POSIX standard.

Unlike visual ("full-screen") editors such as vi/vim, ed is a line editor. It pioneered and influenced many features seen in popular tools such as grep, sed, ex, and vi/vim.

ed commands can be stored in scripts; notably, the diff tool can be set to generate ed commands when using the -e command line option.

Questions about scripting with ed are likely to be suitable for Stack Overflow; questions about interactive usage might be better suited for Unix & Linux or Super User.

References

66 questions
2
votes
1 answer

ed HERELINE substitute pattern fails

Suppose you want to make an edit in all files containing a pattern. For instance, change all '2017' to '2018'. Many suggestions exist for perl, sed, and a variety of others. The ed editor is significantly simpler, if it can be made to work. Given a…
jlettvin
  • 1,113
  • 7
  • 13
2
votes
3 answers

Adding Text using ed to the End of a Specific Line within a File

I have two files, both contain tens of thousands of lines. I'm currently taking a string (Z1234562) from file_one.txt and trying to see if its on file_two.txt. If it's found on file_two.txt, I'm returning the line number the match was on -- in this…
2
votes
2 answers

Wishing that sed had an equivalent for ed's handy j command

It has always bugged me that sed doesn't have a j command, like ed does. This question asks how to join lines in general, and there are a bunch of good answers, many featuring other tools like awk and perl. And there are some sed solutions, too,…
Steve Summit
  • 45,437
  • 7
  • 70
  • 103
2
votes
3 answers

Add contents of 1 file to the top of another file

I need to insert text from 1 file at the top of a large number of files in a directory and its subdirectories. I have been able to do this successfully on a file by file basis using ed: ed -s FileToAddTo.txt <<< $'0r TextToAdd.txt\nw' However, when…
RunLoop
  • 20,288
  • 21
  • 96
  • 151
2
votes
5 answers

Remove only single spaces in text file with sed, perl, awk, tr or anything

I have a rather large text file where there is an extra space between every character; I t l o o k s l i k e t h i s . I'd like to remove those extra characters so It looks like this. via the Linux terminal. I can't seem to find anyway to…
2
votes
4 answers

vim, ed or sed multiple search and replace on a given file

I want do a series of "search and replace" on a given file, say file.txt. For example, s/foo/bar/g s/abc/xyz/g s/pqr/lmn/ g/string-delete/d and so on. How shuld I write all these actions in a script file and then run them on a single go on the…
Tem Pora
  • 2,043
  • 2
  • 24
  • 30
2
votes
1 answer

Temporary file deleted

I'm working on ed (yes, the editor) source code. The program uses a scratch file, opened with tmpfile, as a buffer. But, whenever I run the program, lsof always report the temporary file as deleted! (and in fact it's not there). Why?
1
vote
2 answers

How do I use relative line numbers with patterns in ed

In attempting to use ed to delete lines around a certain pattern I've been driving my self nut ts. What I'd like to do is match a pattern, and then delete lines around it. I've tried several variations ed test.txt <<<< $'/pattern/-1,+1d\nwq' ed…
Catskul
  • 17,916
  • 15
  • 84
  • 113
1
vote
1 answer

Using ed line editor for matching lines with a regular expression

i am trying to use ed command in with regular expressions participants.txt #Team:Volgnummer:Nationaliteit:Auto:Klasse DECONINCK Nico - DECONNINCK Gregory:0:B/B:OPEL Kadett:1A DECONINCK Harry - Verhelst Jos:1:B/B:OPEL Kadett:1A DEBRUYNE Jurgen -…
DOS HASAN
  • 323
  • 1
  • 9
1
vote
2 answers

Shell script: Insert multiple lines into a file ONLY after a specified pattern appears for the FIRST time. (The pattern appears multiple times)

I want to insert multiple lines into a file using shell script. Let us consider my original file: original.txt: aaa bbb ccc aaa bbb ccc aaa bbb ccc . . . and my insert file: toinsert.txt 111 222 333 Now I have to insert the three lines from the…
Diving
  • 784
  • 1
  • 9
  • 17
1
vote
1 answer

How to refetch the access token in a Python script automatically after it expires?

so I am working on fetching data from an api using access token only. I have created two python scripts, one for fetching the token and the other for fetching data. I have created a common variable 'token' for both scripts. However when token…
Ahmad Kurdi
  • 13
  • 1
  • 4
1
vote
1 answer

How to use diff3 with ed

How to use diff3 together with ed? My attempt below does not match diff3 --merge output, so I must be doing something wrong. Context: I've ported OpenBSD's diff3prog.c utility to be used in BusyBox, which has diff and ed. cat <<- EOF >…
Vadim Kantorov
  • 930
  • 1
  • 10
  • 28
1
vote
1 answer

Why does this command work in the terminal but not in a makefile?

I have a command which runs successfully from the command line and turns this: 1 first line 2 second line 3 third line 4 fourth line extra bit 5 fifth line 6 sixth line into this: 1 first line 2 second line 3 third line 4 fourth line; extra bit 5…
mherzl
  • 5,624
  • 6
  • 34
  • 75
1
vote
2 answers

Insert a text at the beginning of a file + stdout, stderr

I have function "backup", and output for this function from the console is also redirected to a file, and it's done as follows: backup > >(tee -a ./log.txt) 2>&1 it works, but I want to add new output data to the beginning of a file, and looks like…
KarlsD
  • 649
  • 1
  • 6
  • 12
1
vote
1 answer

Append or write to file using here-strings

How can I write to a file or append a string to a file using ed only? I have knowledge of other editors but this particular form of writing in a bash script with ed confuses me a lot: ed fileName <<< $'a textToWriteInFile\nwq' The previous line…