Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sorting within a variable

Status
Not open for further replies.

columb

IS-IT--Management
Feb 5, 2004
1,231
EU
I have a script which uses ssh to access a number of remote systems. There are a number of ways in which these systems can be chosen and I build up a list. Typically, at the end of the input stage the list might look like
Code:
echo $_boxes
40 42 44 46 48 50 52 54 40 42 44 46 48 50 52 54 100 102 104 108 110 112
As you can see there are duplicate entries and they're not in order.
I tried
Code:
_boxes=$(echo _boxes | sort -un)
but sort sees this as one line with multiple fields and, as such, does nothing.

Is there a way to persuade sort to do what I want, or should I be trying something else.

On the internet no one knows you're a dog

Columb Healy
 
what about this ?
Code:
_boxes=$(echo $_boxes | tr ' ' '\n' | sort -un)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Feherke
One of my favourite quotes, I believe from Monsieur Citroen when testing his first gear box, is, if you'll excuse my poor French
Monsieur Citroen said:
C'est brutale, mais il marche
Thanks as ever


On the internet no one knows you're a dog

Columb Healy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top