dinsdag 25 september 2012

String manipulation with sed

String manipulation with sed

First example

$ echo "Hello world" | sed 's/o/i/g'
Helli wirld

Example with other seperator

$ echo "Hello world"  |sed "s@o@i@g"
Helli wirld

Example with slash forward

$ echo "Hello/ world"  |sed "s@/@.@g"
Hello. world

Example with slash backwards

$ echo "Hello\ world"  |sed "s@\@.@g"
sed: 1: "s@\@.@g": unterminated substitute in regular expression
$ echo "Hello\ world"  |sed "s@\\@.@g"
sed: 1: "s@\@.@g": unterminated substitute in regular expression
$ echo "Hello\ world"  |sed "s@m@.@g"
Hello\ world
$ echo "Hello\ world"  |sed "s@\\\@.@g"
Hello. world

Geen opmerkingen:

Een reactie posten