[[sed]]

sed

Search and replace a pattern in all files in current directory:

for i in *; do sed 's/@domain.tld/@lists.domain.tld/g' $i > $i.new; rm $i; mv $i.new $i; done

Show logged in users, delete first 4 lines, print only username and computer name and finally sort the list:

smbstatus -b | sed '1,4d' | awk '{print$2"\t\t"$4}' | sort

Search row and append to it:

sed '/^allowed_hosts/ s/$/,nagios3/' nrpe_local.cfg
 
# to edit the file in place:
sed -i.bak '/^allowed_hosts/ s/$/,nagios3/' nrpe_local.cfg
# this will create a backup file named nrpe_local.cfg.bak

Search a row and insert a line below:

sed -i.bak -e '/allow \^192\\\.168\\\.0\\\.10\\$/a \allow \^192\\\.168\\\.0\\\.20\\$' munin-node.conf
linux/sed.txt · Last modified: 2012-11 by tb
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0 ipv6 ready