FUN WITH LINUX

sed: Schedule a job which comments out specific lines in a file

16 February 2015

If you want to comment out specific lines in a file you can use sed. Let’s assume we have an “alloweduser”-file, and we want to disable all users starting with “adm” on a specific date.

this might be our /etc/allowedusers-file:

doctor
rose
martha
clara
adm01
adm02
adm03

now we want to comment out all lines starting with “adm” on 20th february 2015

dr@tardis:/etc/allowedusers# at 15-02-20
warning: commands will be executed using /bin/sh
at> sed -i.bak -e "s/adm/\#&/g" /etc/allowedusers
at> 
job 5 at Fri Feb 20 14:24:00 2015

This will replace all lines with “adm” to “#adm..” AND it creates a backup-file /etc/allowedusers.bak with our old entries.

[ Linux  Sysadmin  Tricks  sed  ]
Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution 3.0 Unported License.

Copyright 2015-present Hoti