Introduction
Alice and Bob are writers who are collaborating on a new book. They’ve decided to use Git as their tool for collaborative edition, and a very ancient computer with a model M keyboard attached to it.
To get started, they’ll need to set up a Git repository for the book. This will allow them to track changes to the book over time, collaborate on the book together, and easily merge their changes into a single version of the book.
Note: this tutorial assumes you have access to both git
and ed
commands. If it is not true, feel free to install them:
sudo apt update
sudo apt install -y git ed
About ed
ed is the original Unix editor. It is a sophisticated piece of software that will help us to manipulate text files in a precise way.
It can be used both programmatically and with an interactive shell, but mostly we will take advantage of its automation characteristics to update the content of the book.
For example, this script will insert a message in the line number two of the example.txt
file, w
rite the updated file on disk and q
uit from ed
:
ed example.txt << EOF
2i
This text will be inserted on line number two.
.
w
q
EOF
Exercise
This exercise contains the solution hidden on it. We are going to use this format during the training: invest some time trying to solve the proposed problem, and ask for support to your trainer if you get lock. But, in case of desperation, you can always click on the Show solution button to get a tip or even the whole answer… after a few minutes of having started to solve it ;)
Now that we are familiar with the format, **let's solve our first challenge**:We are going to practice with the ed
command. Start by creating a file:
cat << EOF > myfile.txt
aaaaaaaaaaa
bbbbbbbbbbb
ccccccccccc
ddddddddddd
EOF
cat myfile.txt
Now, use what you have learnt to insert a line of 0
(zeros) between all those bbbbbbbbbbb
and ccccccccccc
. Remember: ed
is a line-based text editor.
Hint:
ed myfile.txt << EOF
█i
00000000000
.
█
█
EOF
ed
command. Start by creating a file:cat << EOF > myfile.txt
aaaaaaaaaaa
bbbbbbbbbbb
ccccccccccc
ddddddddddd
EOF
cat myfile.txt
0
(zeros) between all those bbbbbbbbbbb
and ccccccccccc
. Remember: ed
is a line-based text editor.ed myfile.txt << EOF
█i
00000000000
.
█
█
EOF
Solution:
ed myfile.txt << EOF
3i
00000000000
.
w
q
EOF
cat myfile.txt