The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to sort, and count unique data all at once? amatuer_lee_3 Shell Programming and Scripting 16 04-14-2009 11:22 PM
put the contents of this file into a variable with multiple lines Nomaad Shell Programming and Scripting 3 04-23-2008 01:39 AM
Sort and Unique in Perl deepakwins Shell Programming and Scripting 20 02-11-2008 09:25 PM
Save contents of a Variable carl_vieyra UNIX for Dummies Questions & Answers 1 02-27-2007 12:27 AM
adding contents of a variable to a command gammarays Shell Programming and Scripting 2 02-08-2005 01:39 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-20-2008
praveenbvarrier praveenbvarrier is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 15
unique sort contents of a variable

Hi ,

I have

#echo $var1
#hdisk2 hdisk3 hdisk0 hdisk2

Now I need to remove duplicate entries from this . ie. after sorting it should only have

hdisk2 hdisk3 hdisk0 .

I can have these values in a array as well . I understand we can use sort -u to remove the duplicates in a coloumn but here it is row and hence I am stuck
  #2 (permalink)  
Old 05-20-2008
Franklin52 Franklin52 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2007
Posts: 4,346
You can try something like:


Code:
new_var=$(echo "$var"|tr " " "\n"|sort|uniq|tr "\n" " ")

Regards
  #3 (permalink)  
Old 05-20-2008
praveenbvarrier praveenbvarrier is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 15
waah , thats gr8 ,

and yeah , this also didthe job , i replaced the uniq with sort -u

new_var=$(echo "$var1"|tr " " "\n"|sort -u|tr "\n" " ")


Thank You
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 10:35 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0