Bash Strip Preceeding White Space

[Solved] Bash Strip Preceeding White Space | Perl - Code Explorer | yomemimo.com
Question : bash strip preceeding white space

Answered by : charlesalexandre-roy

# Basic syntax:
sed 's/^ *//g'
# Example usage:
echo ' text' # Printing without sed command
--> text
echo ' text' | sed 's/^ *//g' # Pipe to sed command
--> text
# Note, use the following to remove all whitespace from the end of every line
sed 's/ *$//g'

Source : https://linuxhint.com/trim_string_bash/#:~:text=Use%20sed%20's%2F%5E%20*%2F%2F,command%20and%20%5B%5B%3Aspace%3A%5D%5D.&text=%24%20echo%20%22%24Var%20are%20very%20popular%20now.%22 | Last Update : Mon, 05 Oct 20

Question : remove white space from stering in bash

Answered by : sachin-verma

$ var='abc def'
$ echo "$var"
abc def
# Note: flussence's original expression was "${var/ /}", which only replaced the *first* space char., wherever it appeared.
$ echo -n "${var//[[:space:]]/}"
abcdef

Source : | Last Update : Tue, 02 Aug 22

Answers related to bash strip preceeding white space

Code Explorer Popular Question For Perl