Popular
Latest Articles
- How to Secure your Cisco Router
- Creating CLI Views on a Cisco Router
- Configuring TACACS+ on a Cisco Router
- How to enable SDM on your router
- Build a Samba Server on Redhat / CentOS
- How to set the Time / Date and Timezone in CentOS
- How to install SSH on Solaris 10 x86
- ESX4 - How do I turn on/off a Virtual Machine from the command line ?
UNIX - Sed By Example
Wednesday, 24 September 2008 10:14
Find and Replace
Action - Will replace all words arp with /sbin/arp in the file /etc/init.d/proxyarp
sed -i 's|arp|/sbin/arp|g' /etc/init.d/proxyarp
Find and Delete
To remove blank lines,
sed -e '/^$/d' file.txt
This will remove word, word1, or word2 from the file input.txt
sed 's/word\|word1\|word2//g' input.txt
Change the first instance on each line
This will substitute the 1 instance of the word dog for cat on each line.
sed 's/dog/cat/1' newfile.txt
Change case
This will change all the text to uppercase.
sed -e 's/.*/\U&/g' input.txt
Changing multiple files
Below will change all the files in /etc from word1 to word2.
sed -i 's/word1/word2/g' /etc/*
We have 19 guests online