Signal9Signal9 — home
online
back to labs

Line Surgery: Search-Replace and Delete in vim

MediumText Editors15-20 min
The brief

You can open vim and insert a character — now do real editing without arrow-key drudgery. The server inventory at /root/inventory.conf has two problems a whole-file command fixes in one stroke each. First, someone fat-fingered the role 'database' as 'databse' — and it appears on more than one line, so fixing it by hand is exactly the kind of repetitive edit vim's substitute command exists to kill. Second, a host was decommissioned but its line is still in the file; that whole line needs to go.

Open the file in vim and make two changes: (1) fix EVERY occurrence of 'databse' to 'database', and (2) delete the entire line for the decommissioned host (the one whose status is 'DECOMMISSIONED'). Save and quit. Grading checks the resulting file, so any method works — but this is the lab to practice :%s/old/new/g and dd.

What you'll do
  • Fix every 'databse' typo to 'database' (use :%s/databse/database/g)
  • Delete the entire line whose status is DECOMMISSIONED (put the cursor on it and press dd)
  • Save the file and quit vim

Hands-on lab: you work on a real Linux box in your browser, graded on the machine's actual state.