uttam
uttam

Reputation: 75

How to sort string alphabetically in shell script

String sorting algorithm in shell script.

I have done it for numbers,but not able to do for string.

EX:- I am kohali. It should be like am i kohali

Upvotes: 0

Views: 6892

Answers (1)

Vishnu T S
Vishnu T S

Reputation: 3914

Below script will help you

 str='I am kohali'
    for i in `echo $str`; do
        echo $i
    done | sort

Below one will accept input from user

read -p "Enter your string:" str
for i in `echo $str`; do
    echo "$i"
done | sort

Output

am I kohali

Upvotes: 2

Related Questions