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"...")
 
No edit summary
Line 2: Line 2:
See also [[gnu sed]].
See also [[gnu sed]].


= Usage =
For overview see [[gnu sed]].
 
= BSD differences =
<blockquote>
<blockquote>
<source lang="bash">
<syntaxhighlight lang="bash">
# Replace 'aaa' with 'bbb'
cat echo "aaa_stuff_aaa" \
| sed 's_aaa_bbb_g'
 
 
# 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'
 
 
# 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><!-- BSD differences -->

Revision as of 14:03, 16 October 2021

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

For overview see gnu sed.

BSD differences

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