2020-02-02 10:29:36 +00:00
|
|
|
# Preview a file edit, via substitution.
|
|
|
|
sudo sed 's/Name=Xfce Session/Name=Xfce_Session/' /usr/share/xsessions/xfce.desktop
|
|
|
|
|
2020-02-02 10:45:33 +00:00
|
|
|
# Replace the same string more than once per line (appending g flag), via substitution.
|
2020-02-02 10:29:36 +00:00
|
|
|
sudo sed 's/Name=Xfce Session/Name=Xfce_Session/g' /usr/share/xsessions/xfce.desktop
|
|
|
|
|
|
|
|
# Edit a file (adding -i flag), via substitution, in-place; changes are made to the file(s).
|
Add 'sed' and give example of in-place changes
The `-i` flag with `sed` means "in-place", if you're curious; the use
thereof allows for making actual changes to the file, not just
superfluously, such as for additional parsing.
The `s///` is a simple substitution, wherein the `s` marks that it's a
substitution, the `/` marks the boundaries*, and the final boundary can
be suffixed with various flags, such as `g`, for global operations, -
and `i`, for case-insensitive operations.
* required, but the slash can switched for something else, if needed, -
such as `|`, which is commonly used for paths. For example:
`s|/path/to/file|/path/file|`
2019-11-06 15:22:56 +00:00
|
|
|
sudo sed -i 's/Name=Xfce Session/Name=Xfce_Session/' /usr/share/xsessions/xfce.desktop
|
2020-02-02 10:29:36 +00:00
|
|
|
|
|
|
|
# It can become necessary to escape special characters in your string.
|
2020-02-02 10:32:28 +00:00
|
|
|
sed -i 's/\/path\/to\/somewhere\//\/path\/to\/anotherplace\//' /tmp/filetoedit
|
2020-02-02 10:29:36 +00:00
|
|
|
|
|
|
|
# Change your sed delimiter to a pipe to avoid escaping slashes.
|
2020-02-02 10:32:28 +00:00
|
|
|
sed -i 's|/path/to/somewhere/|/path/to/anotherplace/|' /tmp/filetoedit
|