diff options
author | johannst <johannst@users.noreply.github.com> | 2024-02-15 23:29:57 +0000 |
---|---|---|
committer | johannst <johannst@users.noreply.github.com> | 2024-02-15 23:29:57 +0000 |
commit | bac8a5d2822835cf47175d1162030653fadd5c09 (patch) | |
tree | 28f312a114cf95ac799daac2a2caec4b8612d84d /tools/sed.html | |
parent | bfc5ce4bc01e5eb28969eefcc01ecfefa2601fdf (diff) | |
download | notes-bac8a5d2822835cf47175d1162030653fadd5c09.tar.gz notes-bac8a5d2822835cf47175d1162030653fadd5c09.zip |
deploy: 4485708c972815bbb6df7f5a228683aa855d553d
Diffstat (limited to 'tools/sed.html')
-rw-r--r-- | tools/sed.html | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tools/sed.html b/tools/sed.html index 5796ea9..f44fb19 100644 --- a/tools/sed.html +++ b/tools/sed.html @@ -182,6 +182,8 @@ -i edit file in place -i.bk edit file in place and create backup file (with .bk suffix, can be specified differently) + --follow-symlinks + follow symlinks when editing in place -e SCRIPT add SCRIPT to commands to be executed (can be specified multiple times) -f FILE add content of FILE to command to be executed @@ -232,6 +234,12 @@ echo -e 'aa\nbb' | sed '2aABC' echo -e 'aa\nbb' | sed '2cABC' # aa # ABC + +# Insert before pattern match. +echo -e 'aa\nbb' | sed '/bb/i 123' +# aa +# 123 +# bb </code></pre> <h3 id="substitute-lines"><a class="header" href="#substitute-lines">Substitute lines</a></h3> <pre><code class="language-sh"># Substitute by regex. @@ -244,6 +252,20 @@ echo -e 'aafooaa\ncc' | sed 's/foo/MOOSE/' # BAR # bar </code></pre> +<h3 id="edit-inplace-through-symlink"><a class="header" href="#edit-inplace-through-symlink">Edit inplace through symlink</a></h3> +<pre><code class="language-sh">touch file +ln -s file link +ls -l link +# lrwxrwxrwx 1 johannst johannst 4 Feb 7 23:02 link -> file + +sed -i --follow-symlinks '1iabc' link +ls -l link +# lrwxrwxrwx 1 johannst johannst 4 Feb 7 23:02 link -> file + +sed -i '1iabc' link +ls -l link +# -rw-r--r-- 1 johannst johannst 0 Feb 7 23:02 link +</code></pre> </main> |