Quantcast
Channel: Adam Palmer, PHP Programmer, Website Security Consultant » Linux
Viewing all articles
Browse latest Browse all 15

String replacement with sed

$
0
0

Sed – stream editor is a powerful tool to manipulate strings. It will take STDIN as well as operating on a file:

The most common usage is to replace text:  echo “this is a test string” | sed s/i/z/g will replace every instance of ‘i’ with a ‘z’:  thzs zs a test strzng

You can delete a particular word with say echo “this is a test string”| sed s/test//g leaving: this is a  string

You can operate on a file with:

echo “this is a test string” >> file; sed -e s/test//g file Leaving: this is a  string

You can also use regular expressions with sed.


Viewing all articles
Browse latest Browse all 15

Trending Articles