Is there a way to grep for a regular expression on an Ubuntu server and then find and replace it with another string? I am using the following command right now, but it doesn't account for actually changing the grepped string:
grep --recursive --ignore-case “string”
If I use awk or sed how would I write it to replace for instance "wavbyte" with "gitship" for all instances where "wavbyte" occurs for my entire server?
“string”
, including the quotes. You want"string"
(or probably even better,'string'
, unless you plan on using parameter expansion in the search term). – Benjamin W. Oct 01 '18 at 00:51grep
isn't used to replace strings. It's used for finding strings. To replace them, you needsed
orawk
. – Nasir Riley Oct 01 '18 at 00:52grep --recursive --files-with-matches
to construct a list of file names to be passed tosed
– steeldriver Oct 01 '18 at 00:58sed-ri(){ e="$1"; shift; find "$@" -type f -print0 | xargs -0 sed -i "$e"; }
thensed-ri 's/foo/bar/g' files and dirs ...
– Oct 01 '18 at 02:04