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
9
votes
3 answers

Replace a line with multiple lines in a file

I want to replace a single line in a file with multiple lines, e.g., I want to replace a particular function call, say, foo(1,2) with if (a > 1) { foo(1,2) } else { bar(1,2) } How can I do it in bash?
ravi
  • 3,304
  • 6
  • 25
  • 27
7
votes
6 answers

Editing the last instance in a file

I have a huge text file (~1.5GB) with numerous lines ending with ".Ends". I need a linux oneliner (perl\ awk\ sed) to find the last place '.Ends' appear in the file and add a couple of lines before it. I tried using tac twice, and stumbled with my…
user2141046
  • 862
  • 2
  • 7
  • 21
6
votes
4 answers

Delete third-to-last line of file using sed or awk

I have several text files with different row numbers and I have to delete in all of them the third-to-last line . Here is a sample file: bear horse window potato berry cup Expected result for this file: bear horse window berry cup Can we delete…
BADS
  • 141
  • 8
6
votes
2 answers

How to escape period in ed

I'm studying the ed text editor. To exit from input mode, a user should enter a line a single period (.). Let's say I want to enter the period as text. I thought of a workaround: first, I insert something like ... Then, I replace .. with .. But my…
Daniil Iaitskov
  • 5,525
  • 8
  • 39
  • 49
5
votes
3 answers

Inserting a newline in the middle of a line in ed (editor)

Suppose I have opened a text file in ed, and the current line looks like this: This is sentence one. Here starts another one. Now I want to put a newline after one. , such that the new sentence starting with Here starts occupies the next line. How…
5
votes
2 answers

XMLStarlet Namespaces definition

I need your help on the Namespaces for XMLStarlet. (never saw a library that badly explained) I have an XML file like:
5
votes
3 answers

How can I provide stdin to ed, which need a filename?

Need some unix shell basic here: For command that I see no "-" target in , say ed: print '%-2p\nq' | ed -s FILE Can I provide a stream from stdout of some cmd, rather than FILE name, as the data to be processed: SomeCMD | ed -s SOMETHING_MAGICAL…
MeaCulpa
  • 881
  • 1
  • 6
  • 14
4
votes
2 answers

How can I prevent ed printing match results?

I use ed in a bash script to search a file; the / command will display the content, which I don't want. I tried to redirect >/dev/null 2>&1 but that didn't work for me. text file foo.txt: a b c bash script bar.sh: ed -s foo.txt << EOF /b/ EOF >…
redmark
  • 131
  • 8
4
votes
1 answer

How can heredocs be used with xargs?

Background I'm looking to strip any # TODO comments from some python source code files output by git archive before sending it off. I'm looking to do so from a script that will be run from a variety of *nix OSes, so it should be as POSIX-compliant…
Pewpewarrows
  • 823
  • 6
  • 13
3
votes
6 answers

How to move block of text and next nth line following a pattern to end of file?

I have this ssh config that needs to be edited. Host vps6 HostName 123.456.789.00 User dylan Port 123 Host vps4 HostName 123.456.789.00 User dylan Port 123 # old server Host vps3-old HostName 123.456.789.00 User dylan …
Liso
  • 188
  • 2
  • 14
3
votes
3 answers

Using ed to manipulate files matched by find

Following the bash-hackers wiki's recommendation, I want to edit files using ed. In particular I want to do the following with ed instead of sed: find . -type f -exec sed -i -e 's/a/b/g' {} \; I see that ed doesn't have opt like sed's -e, so as far…
theosp
  • 7,439
  • 3
  • 23
  • 24
3
votes
2 answers

why 'ed' also named 'red' in linux

Recently I play with an awesome programming language red. After I downloaded it on my Linux Box, and typed red --version, I got something unexpected: $ red --version GNU ed version 0.2 then I look up ed's manual, it's said it also named red, but…
Sonny
  • 182
  • 1
  • 1
  • 9
2
votes
2 answers

For loop in Makefile has no effect

I have a one-line script passed into the foreach function in a Makefile, as shown below: flag: $(foreach f, $*.txt, printf "%s\n" 0a "$(grep -o '[0-9]\+' $f | sed 's/.*/read \"&\"/')" "" . w q | ed $f) What this script line does could be…
day
  • 2,292
  • 1
  • 20
  • 23
2
votes
1 answer

How to append a line with the output of a command using ed

I am writing a bourne shell script in Linux, and I am using ed to append text to the end of the file. I MUST use ed to do this task. What I need the appended text to look like is this Modified on: current_date Where current_date is the output of…
Kyounge1
  • 23
  • 3
2
votes
4 answers

How to delete an specific line of a file using POSIX shell scripts?

I want do delete, say line number three of the file a. How can I do this with tools like sed or awk in a way that it's compatible with the POSIX specification? I know I could do sed -i '3d' a, but the -i flag is not specified by POSIX for sed. Of…
Luis Lavaire.
  • 599
  • 5
  • 17
1
2 3 4 5