Bsd sed: Difference between revisions

From wikinotes
(Created page with "Sed allows you to search/replace within lines/files.<br> See also gnu sed. = Usage = <blockquote> <source lang="bash"> # Replace 'aaa' with 'bbb' cat echo "aaa_stuff_aaa"...")
 
 
(3 intermediate revisions by the same user not shown)
Line 2: Line 2:
See also [[gnu sed]].
See also [[gnu sed]].


= Usage =
= Documentation =
<blockquote>
<blockquote>
<source lang="bash">
{| class="wikitable"
# Replace 'aaa' with 'bbb'
|-
cat echo "aaa_stuff_aaa" \
| <code>man sed</code> || https://www.freebsd.org/cgi/man.cgi?query=sed&format=html
| sed 's_aaa_bbb_g'
|-
 
|}
 
</blockquote><!-- Documentation -->
# Regex
cat echo "aaa_stuff_aaa" \
| sed 's_[a]*_b_g'
 
# Group matching (\2 is a variable that refers to the
# second match group. In this case, 'stuff'
cat echo "aaa_stuff_aaa" \
| sed 's_\([a]*\)\(stuff\)_\2\n'


= Overview =
<blockquote>
See [[gnu sed]].
</blockquote><!-- Overview -->


= Differences from GNU =
<blockquote>
<syntaxhighlight lang="bash">
# BSD replace file contents
# BSD replace file contents
sed -i ".bak" "s_aaa_bbb_g" /path/to/file
sed -i ".bak" "s_aaa_bbb_g" /path/to/file
</source>
</syntaxhighlight>
</blockquote><!-- Usage -->
</blockquote><!-- Differences from GNU -->

Latest revision as of 14:06, 16 October 2021

Sed allows you to search/replace within lines/files.
See also gnu sed.

Documentation

man sed https://www.freebsd.org/cgi/man.cgi?query=sed&format=html

Overview

See gnu sed.

Differences from GNU

# BSD replace file contents
sed -i ".bak" "s_aaa_bbb_g" /path/to/file