Bash Trim: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 10: Line 10:
leading_space_removed=${var_name##[[:space:]]}
leading_space_removed=${var_name##[[:space:]]}
</syntaxhighlight>
</syntaxhighlight>
With <code>sed<code>:
With <code>sed</code>:
<syntaxhighlight lang='bash'>
<syntaxhighlight lang='bash'>
sed -e 's/^ *//' -e 's/ *$//'
sed -e 's/^ *//' -e 's/ *$//'
</syntaxhighlight>
</syntaxhighlight>
==Trim New Line==
==Trim New Line==
<font color=darkkhaki>TODO</font>
<font color=darkkhaki>TODO</font>

Revision as of 01:06, 2 March 2024

Internal

Overview

Trim Spaces

With variable manipulation:

trailing_space_removed=${var_name%%[[:space:]]}
leading_space_removed=${var_name##[[:space:]]}

With sed:

sed -e 's/^ *//' -e 's/ *$//'

Trim New Line

TODO