Bash Trim

From NovaOrdis Knowledge Base
Revision as of 01:08, 2 March 2024 by Ovidiu (talk | contribs) (→‎Trim New Line)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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

With tr:

tr -d