Sorting out unique values from output of for loop.

Hi ,

i have a belwo script which is used to get sectors per track value extarcted from Solaris machine:

 
 for DISK in /dev/dsk/c*t*d*s*; do value=`prtvtoc "$DISK" | sed -n -e '/Dimensions/,/Flags/{/Dimensions/d; /Flags/d; p; }' | sed -n -e '/sectors\/track/p'`; if [ -n "$value" ]; then echo "SectorsPerTrack=$DISK:$value"; else  echo "$value" >/dev/null; fi; done 2>/dev/null

the output is as below :

 
SectorsPerTrack=/dev/dsk/c1t0d0s0:*      63 sectors/track
SectorsPerTrack=/dev/dsk/c1t0d0s1:*      63 sectors/track
SectorsPerTrack=/dev/dsk/c1t0d0s10:*      63 sectors/track
SectorsPerTrack=/dev/dsk/c1t0d0s11:*      63 sectors/track
SectorsPerTrack=/dev/dsk/c1t0d0s12:*      63 sectors/track
SectorsPerTrack=/dev/dsk/c1t0d0s13:*      63 sectors/track
SectorsPerTrack=/dev/dsk/c1t0d0s14:*      63 sectors/track
SectorsPerTrack=/dev/dsk/c1t0d0s15:*      63 sectors/track
SectorsPerTrack=/dev/dsk/c1t0d0s2:*      63 sectors/track
SectorsPerTrack=/dev/dsk/c1t0d0s3:*      63 sectors/track
SectorsPerTrack=/dev/dsk/c1t0d0s4:*      63 sectors/track
SectorsPerTrack=/dev/dsk/c1t0d0s5:*      63 sectors/track
SectorsPerTrack=/dev/dsk/c1t0d0s6:*      63 sectors/track
SectorsPerTrack=/dev/dsk/c1t0d0s7:*      63 sectors/track
SectorsPerTrack=/dev/dsk/c1t0d0s8:*      63 sectors/track
SectorsPerTrack=/dev/dsk/c1t0d0s9:*      63 sectors/track

Can someone help me to tune this script to give me only the unique value of sectors/track value out of the for loop :
output in the below fashion(only the unique values and * removed from the output):

SectorsPerTrack=/dev/dsk/c1t0d0s0:63 sectors/track

thanks in advance :slight_smile:

redirect "Your command output to a sed and do replace '*' with space and then do a sort -u on it"

Thanks Panyam for help..
Could you please let me know how this can be done in the for loop which i have posted..actually i am bit confused where to place this logic.

Does the below helps?

for DISK in /dev/dsk/c*t*d*s*; 
do 
value=`prtvtoc "$DISK" | sed -n -e '/Dimensions/,/Flags/{/Dimensions/d; /Flags/d; p; }' | sed -n -e '/sectors\/track/p'`; 
if [ -n "$value" ]; 
then 
echo "SectorsPerTrack=$DISK:$value"; 
else  
echo "$value" >/dev/null; 
fi; 
done | sed 's/*//g' | sort -u

not exactly.. but thanks a lot for providing me hint i have modified it a bit and here is the script and its output :

 
for DISK in /dev/dsk/c*t*d*s*; do value=`prtvtoc "$DISK" | sed -n -e '/Dimensions/,/Flags/{/Dimensions/d; /Flags/d; p; }' | sed -n -e '/sectors\/track/p'`; if [ -n "$value" ]; then echo "SectorsPerTrack=$value"; else echo "$value" >/dev/null; fi; done 2>/dev/null | sed -e 's/*//g' -e 's/sectors\/track//g' -e 's/ //g' | sort -u

output:
SectorsPerTrack=63