sh, ksh: command to remove front spaces from a string?

dear pro-coders,
is there any command out there that takes out the front spaces from a string?

sample strings:

 4 members
  5 members
   3 members 

but it has to be like so:

4 members
5 members
3 members

The Korn shell has the typeset -L option which can left justify a string
i.e. remove leading spaces.

Hi.

Here are two methods:

#!/usr/bin/env ksh

# @(#) s1       Demonstrate front-trim blanks.

set -o nounset
echo

## Use local command version for the commands in this demonstration.

echo "(Versions of codes used in this script -- local code \"version\")"
echo "pdksh version: $KSH_VERSION"
version cat sed

cat >data1 <<EOF
 4 members
   5    members
      3 members
EOF

echo
echo " Input file:"
cat -vet data1

echo
echo " Front-trimming with variable pattern:"
while IFS= read line
do
  echo " Original line:    |$line|"
  t1=${line##+( )}
  echo " Transformed line: |$t1|"
done < data1

echo
echo " Fast front-trimming with sed:"
sed -e 's/^ *//' data1

exit 0

Producing:

% ./s1

(Versions of codes used in this script -- local code "version")
pdksh version: @(#)PD KSH v5.2.14 99/07/13.2
cat (coreutils) 5.2.1
GNU sed version 4.1.2

 Input file:
 4 members$
   5    members$
      3 members   $

 Front-trimming with variable pattern:
 Original line:    | 4 members|
 Transformed line: |4 members|
 Original line:    |   5    members|
 Transformed line: |5    members|
 Original line:    |      3 members   |
 Transformed line: |3 members   |

 Fast front-trimming with sed:
4 members
5    members
3 member

See man pages for details. The O'Reilly book "Learning the Korn Shell" would be useful if extensive use of ksh is anticipated ... cheers, drl

echo " Fast front-trimming with sed:"
sed -e 's/^ *//' data1

oh my god! it works! that's exactly what i was looking for :b:
thank you for your great examples, i will study it's other parts later.
and thank you for the O'Reilly hint.

kind regards :slight_smile: