Remove Common Indent

Remove the common leading whitespace from all lines in a multi-line string, normalizing indentation.

Code

General
min_indent=$(echo -e "$s" | grep -v '^$' | sed 's/[^ ].*//' | awk '{print length}' | sort -n | head -1)
echo -e "$s" | sed "s/^.\{$min_indent\}//"

Parameters

Indented multi-line string

Server

More Bash Snippets