Reputation: 119
I have a variable which look something like this:
param="David Salad 100\nMark Fruit 440\nNoam Chicken 440"
I need to sort it according to numbers and then according to Alphabetic order so the out put should be:
Mark Fruit 440 Noam Chicken 440 David Salad 100
I tried to write the following line:
temp=`echo -e $param | sort -srnk3`
echo -e $D
But the out put is "Mark Fruit 440 Noam Chicken 440 David Salad 100" The sort doesn't print any \n 's even though I thought it should.
Upvotes: 1
Views: 182
Reputation: 14940
The sort works
$ param="David Salad 100\nMark Fruit 440\nNoam Chicken 440"
$ echo -e $param | sort -srnk3
Mark Fruit 440
Noam Chicken 440
David Salad 100
you just have to quote the variable ("$temp"
) to see the newlines
$ temp=`echo -e $param | sort -srnk3`
$ echo "$temp"
Mark Fruit 440
Noam Chicken 440
David Salad 100
Upvotes: 3