Back to 1969 or Introduction to Ed - old-school text editor
Tags: history, scripting, shell, bash
Published: 2019-09-01 03:46:44


---
title: Back to 1969 or Introduction to Ed - old-school text editor
published: true
description:Let's immerse in the atmosphere of the late 1960s and touch the history.
tags: history, scripting, shell, bash
cover_image: https://thepracticaldev.s3.amazonaws.com/i/0p53olsdqbj6pf4wcnyj.jpg
---
__1969__
What happened in 1969 Major News Stories include The Beatles' last public performance, on the roof of Apple Records, First Concorde test flight is conducted In France, Boeing 747 jumbo jet makes its debut, Pontiac Firebird Trans Am the epitome of the American muscle car is introduced, Woodstock attracts more than 350,000 rock-n-roll fans, Members of a cult led by Charles Manson murder five people, Chappaquiddick Affair Senator Edward Kennedy, PBS Established, The first man is landed on the moon on the Apollo 11 mission by the United States and Neil Armstrong and Edwin 'Buzz' Aldrin became the first humans to set foot on the Moon.
But there is one more thing ... Awesome string-line text editor: ed. Let's immerse in the atmosphere of the late 1960s and touch the history.

__History__
As early as 1969, the first assembly-language version of [ed](http://www.gnu.org/software/ed/ed.html) was in place. Although later rewritten in [C](https://en.wikipedia.org/wiki/C_(programming_language)), the editor is fundamentally the same program as used then. As [Kernighan](https://en.wikipedia.org/wiki/Brian_Kernighan) and [Plauger](https://en.wikipedia.org/wiki/P._J._Plauger) wrote in 1976, The earliest traceable version of the editor presented here is [TECO](https://en.wikipedia.org/wiki/TECO_(text_editor)), written for the first [PDP-1](https://history-computer.com/ModernComputer/Electronic/PDP-1.html) timesharing system at MIT.

PDP-1:
![PDP-1](https://thepracticaldev.s3.amazonaws.com/i/ra4ogyb5vnl5x8b1bkr2.jpg)

It was subsequently implemented on the [SDS-940](https://en.wikipedia.org/wiki/SDS_940) as the "quick editor'" [QED](https://www.bell-labs.com/usr/dmr/www/qed.html) by [L. P. Deutsch](https://en.wikipedia.org/wiki/L._Peter_Deutsch) and [B. W. Lampson](https://en.wikipedia.org/wiki/Butler_Lampson).

SDS-940:
![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/pr1o6vyacuuxipjq3eb4.jpg)

[K. L. Thompson](https://en.wikipedia.org/wiki/Ken_Thompson) adapted QED for [CTSS](https://en.wikipedia.org/wiki/Compatible_Time-Sharing_System) on the [IBM 7090](https://en.wikipedia.org/wiki/IBM_7090) at [MIT](https://en.wikipedia.org/wiki/Massachusetts_Institute_of_Technology).

IBM 7090:
![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/7obw9gg0jgzw6y7ygicb.jpg)

Later [D. M. Ritchie](https://en.wikipedia.org/wiki/Dennis_Ritchie) wrote a version for the [GE-635](http://www.computinghistory.org.uk/det/15671/GE-635-System-Manual/) at [Bell Labs](https://en.wikipedia.org/wiki/Bell_Labs).
The latest version is ed, a simplified form of QED for the PDP-11, written by Ritchie and Thompson.

PDP-11:
![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/tfloo7ansx85hhlc0e0i.jpg)

This is not to say that ed is the same as the TECO found on some DEC computers. For one thing, TECO is character oriented while ed is line oriented. It seems rather a case of "common ancestry".
During the 1970's, the editor went through countless revisions. Nearly every university had its own modified versions of ed and qed; some had several modified versions. Jay Michlin of Bell Labs wrote (in IBM assembler) a QED for IBM's mainframe [TSO](https://en.wikipedia.org/wiki/Time_Sharing_Option); this was released to Universities in the mid-70's. 
And, of course, ed would visit Berkeley and, while there, mutate into [ex](https://en.wikipedia.org/wiki/Ex_(text_editor)) and [vi](https://en.wikipedia.org/wiki/Vi).
Let's taste it.
During our today’s journey we will consider simple operations with Ed and after we will develop the script that performs the following actions: displaying a list of files that are “children” of a given directory that have a given character set in their names and destroying all other files of a given directory. In the end we will create initializing script that will say hello after login and run another script for searching files.

__Simple operations of Ed__
Let’s create two three-level directories for our experiments.
`mkdir -p {dirA,dirB}/dir1/dir2`
Now we have the following structure (can be output to console with the help of [tree](https://www.ostechnix.com/view-directory-tree-structure-linux/) command):
```
.
├── dirA
│   └── dir1
│       └── dir2
└── dirB
    └── dir1
        └── dir2
```
Create four text files in one of the directories.
`
cd dirA
cd dir1
cd dir2
touch file1.txt file2.txt file3.txt file4.txt
`

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/hvqzzmrs52iwwnhp3fch.png)

__Adding the text to a file with ed.__
Let’s edit the file with ed. Launch it with the filename as a parameter:
`ed file1.txt`
In case when file does not exist ed creates a new one. If it already exists, then ed tells us the length of file. In our case the length is zero. In order to add text to the file we have to switch to adding mode by “a” command.
It appends text to the buffer after the addressed line. The current address is set to last line entered. 
An address represents the number of a line in the buffer. ed maintains a current address which is typically supplied to commands as the default address when none is specified. When a file is first read, the current address is set to the last line of the file. In general, the current address is set to the last line affected by a command.
So, let’s switch to adding mode:
`a`
And type some words:
`Hello!`
`This is text form file1!`
To exit from adding mode type point on the new line:
`.`
To write changes type:
`w`
it prints new size of file. In order to quit from ed:
`q`

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/otxoyl1t4fvtblvcyo1h.png)

__Adding text to the beginning, middle and to the end of file.__
Let's complicate the task a bit and add text to the beginning, middle and end of the file.
Open file again. Let’s print the addressed line by ‘p’ command. It prints us ‘This is a text from file1!’. It’s easy to add the text to the end of file right now. Just switch to adding mode by ‘a’ command and print ‘End’.
Done! Now exit from adding mode by printing ‘.’. To print the first line of document type ‘1p’. It also set the current address to the number of first line. Now we can print ‘i’ command to switch to ‘Insert mode’. This magic command inserts text before the current line and the current address is set to the last line entered. So, after switching to insert mode, let’s type ‘Start’. Then, on the new line type ‘.’ to exit from insert mode. Let’s set the current address to the line number 3. In order to do this just type ‘3p’. Now we can switch to insert mode again and add text to the middle of document. 
In order to print the whole text from file type the following:
`1, $p`
Further save file and quit from ed. Step-by-step way is represented in the picture below.

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/ilerllq86sgaucfkj2bt.png)

Let’s copy file with the help of ‘cp’ command.

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/9hshjjjzsrpe8301xdwz.png)

__Super finder script__
Let’s make the challenge more complicated and develop the script for searching files, which are located in all subdirectories of the current directory, which have in their name a given character set. Then display these files and destroy all other files of a given directory. The script will fart with two parameters. The first parameter is catalog name and the second is the set of symbols (mask). For testing let’s create files in the directories.

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/5bpfu9b5iow6q48ndlyg.png)

Run the script to execute. After check the contents of the directories.

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/ex1aj51l33ndz2duczul.png)

__Initialization script__
Let's develop our initialization script, which say hello by rewriting shell invitation.
Create file “.bashsrc” and edit it in ED editor.

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/jc1vpa30atmkg0pubxvh.png)

In order to check do logout and login into the system back.

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/t6noe2er3ql1uxgjkjpl.png)

Let's perfect our script so that it also runs the nested script created earlier and passes the directory name and part of the file name as parameters to it. And check his work.

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/kfoe92kvbqcloa3mjr49.png)

So, we plunged into the atmosphere of the 1960s, I hope it was fun. That’s it. Thank you!
__Cheers!__