The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 05-14-2008
era era is online now
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,105
It's not at all clear what concept you are looking for. Perhaps you could elaborate on that a bit. In the meantime, here are some hopefully useful exercises.

Code:
var2=$var1   #copy var1 to var2
var2=${var2%abcd}  # trim abcd from end, if present
var2=`echo "$var2" | tr ' ' '\012' | sort | uniq | tr '\012' ' '` # remove duplicate tokens
The token duplicate removal is probably quite different from what you are imagining it would be, and has the unfortunate side effect of sorting the remaining tokens. In this case it doesn't matter, because they were already sorted, but nevertheless it's not a good general-purpose solution if the order of tokens is significant.

Perhaps you should read a tutorial on shell programming at this point; there's a lot of things you can do with variable substitution (${var%trim} is but a single example).
Reply With Quote