As we all know, sed
is greatly efficient to find and replace string, for example find 'a'
and replace it to 'b': sed 's/a/b/g'
.
Is it possible to do this with other command or shell script instead of sed
?
The classic alternative for single letter substitutions is the
Alternatively, you can use the shell's substitution capabilities:
We could give you more specific answers if you explained exactly what problem you are trying to solve. | |||||||||
|
Yes there are a variety of ways to do this. You can use ExamplesSay I have this sample data, in a file
awk
Perl
| |||||
|
If you're working with a file rather than a stream, you could use the standard text editor,
This should be available on any *nix. The comma in Note that, unlike sed's I don't think it's possible to get this working with streams, but then I don't really know much about | |||
|
Using the ancestor ed command : Just printing on STDOUT :
replacing in-place :
| ||||
|
$var=~s/a/b/g
,gsub(/a/,"b",var)
,var.gsub(/a/,'b')
,var.replace(/a/g,'b')
,preg_replace("/a/","b",$var)
,regsub -all a b $var
. Beside that, many tools and languages can also do plain text string replacement. So your question is somehow broad. – manatwork 2 days ago