Sorting out unique values from output of for loop.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sorting out unique values from output of for loop.
# 1  
Old 06-06-2014
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:
Code:
 
 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 :
Code:
 
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):
Code:
SectorsPerTrack=/dev/dsk/c1t0d0s0:63 sectors/track

thanks in advance Smilie
# 2  
Old 06-06-2014
redirect "Your command output to a sed and do replace '*' with space and then do a sort -u on it"
# 3  
Old 06-06-2014
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.
# 4  
Old 06-06-2014
Does the below helps?

Code:
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

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

Code:
 
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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Code to get unique values

Hello All, I am trying to write a script which returns me clientID,programId,userID indicated in bold from the below log files.Log file is having many such data , iam just presenting sample . Sample Log file. hostname 1525867288264 UA:MP:EP491418 http-nio-8080-exec-11 ERROR Get Price... (13 Replies)
Discussion started by: nextStep
13 Replies

2. Shell Programming and Scripting

Sorting unique by column

I am trying to sort, do uniq by 1st column and report this 4 columns tab delimiter table , eg chr10:112174128 rs2255141 2E-10 Cholesterol, total chr10:112174128 rs2255141 7E-16 LDL chr10:17218291 rs10904908 3E-11 HDL Cholesterol chr10:17218291 rs970548 8E-9 TG... (4 Replies)
Discussion started by: fat
4 Replies

3. UNIX for Dummies Questions & Answers

Sorting and saving values based on unique entries

Hi all, I wanted to save the values of a file that contains unique entries based on a specific column (column 4). my sample file looks like the following: input file: 200006-07file.txt 145 35 10 3 147 35 12 4 146 36 11 3 145 34 12 5 143 31 15 4 146 30 14 5 desired output files:... (5 Replies)
Discussion started by: ida1215
5 Replies

4. Shell Programming and Scripting

Finding unique entries without sorting

Hi Guys, I have two files that I am using: File1 is as follows: wwe khfgv jfo jhgfd hoaha hao lkahe This is like a master file which has entries in the order which I want. (4 Replies)
Discussion started by: npatwardhan
4 Replies

5. Shell Programming and Scripting

print unique values of a column and sum up the corresponding values in next column

Hi All, I have a file which is having 3 columns as (string string integer) a b 1 x y 2 p k 5 y y 4 ..... ..... Question: I want get the unique value of column 2 in a sorted way(on column 2) and the sum of the 3rd column of the corresponding rows. e.g the above file should return the... (6 Replies)
Discussion started by: amigarus
6 Replies

6. UNIX for Dummies Questions & Answers

need help sorting/deleting non-unique things

I don't really know much about UNIX commands, so if someone could help me understand how to do this, I'd really appreciate it. I have a text file with data that looks like this (filename: numbers.txt): 1 1 1 1 1 1 1 1 1 2 1 1_2 2_1 1 1 1 1 1 1 1 1 2 1 2 1_2 2_1 1 1 1 1 1 1 1 1 2 1 2 1_2 2_1... (12 Replies)
Discussion started by: zac100
12 Replies

7. UNIX for Dummies Questions & Answers

Sorting with unique piping for a lot of files

Hi power user, if I have this file: file1.txt: 1111 1111 2222 2222 3333 3333 3333 4444 4444 4444 when I run the sort file1.txt | uniq > data1.txt the result is (2 Replies)
Discussion started by: anjas
2 Replies

8. Shell Programming and Scripting

Getting Unique values in a file

Hi, I have a file like this: Some_String_Here 123 123 123 321 321 321 3432 3221 557 886 321 321 I would like to find only the unique values in the files and get the following output: Some_String_Here 123 321 3432 3221 557 886 I am trying to get this done using awk. Can someone please... (5 Replies)
Discussion started by: Legend986
5 Replies

9. Shell Programming and Scripting

to retrieve unique values

Hi all, I have a 10.txt file. In this file 2 words are present by name Active and Inactive and these words are repeated 7000 times. I want to take the unique 2 words from this 7000 lines. Thanks Mahalakshmi.A (3 Replies)
Discussion started by: mahalakshmi
3 Replies

10. Shell Programming and Scripting

sorting file and unique commnad..

hello everyone.. I was wondering is there a effective way to sort file that contains colomns and numeric one. file 218900012192 8938929 8B8DF3664 1E7E2D59D5 0000 26538 1234 74024415 218900012979 8938929 8B8DF3664 1E7E2D59D5 0000 26538 1234 74024415 218900012992 8938929 8B8DF3664... (2 Replies)
Discussion started by: amon
2 Replies
Login or Register to Ask a Question