8.6.14 Edit a file in place using a script
The following script will remove lines 5–10 and lines 16–20 in
place.
#!/bin/bash
ed $1 <<EOF
16,20d
5,10d
w
q
EOF
Here, ed
commands are the same as vi
command-mode
commands. Editing from the back of file makes it easy for scripting.