What some ideas with sort and get unique data


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting What some ideas with sort and get unique data
# 1  
Old 08-19-2009
What some ideas with sort and get unique data

Hi all,

I am writing a script where i can parse through the directory and get common string in two directories i get. The command below SUN_PLATFORM=`$FIND $STREAM_PATH . -depth -name ShareableEntities | $AWK -F"/" '{if($10 ~ /sun5/) print $0}'` gives the following output:-

/net/icebox/vol/local_images/spins/7.1/CQ/7.1.D081110/sun5/ShareableEntities
/net/icebox/vol/local_images/spins/7.1/CC/7.1.D081110/sun5/ShareableEntities


So in next i go store the result in SUN_PLATFORM and do a for loop where i grep file that have .su extension and do a delimiter in awk to print the 1st line. Now i want a way that i can sort the output and get the uniq count(uniq -c) from the two directories. I dont want to write the output the other file and they apply sort and uniq.

If i add to the line in the code below $LS $i | $GREP .su | $AWK -F"_" '{print $1}'| sort | uniq -c . This wont work as it sorts the data in one only one directory and then separately in other directory. The result is not appropriate.

Please suggest.

Thanks
Adsi



Code:
#!/bin/sh

ECHO=/bin/echo
FIND=/bin/find
AWK=/bin/awk
LS=/bin/ls
GREP=/bin/grep

ROOT_PATH=/net/icebox/vol/local_images/spins
STREAM_PATH=$ROOT_PATH/7.1

SUN_PLATFORM=`$FIND $STREAM_PATH . -depth -name ShareableEntities | $AWK -F"/" '{if($10 ~ /sun5/) print $0}'`

for i in $SUN_PLATFORM
do
$ECHO $i
$LS $i | $GREP .su | $AWK -F"_" '{print $1}'
done

# 2  
Old 08-19-2009
something like this?
Code:
#!/bin/sh

ECHO=/bin/echo
FIND=/bin/find
AWK=/bin/awk
LS=/bin/ls
GREP=/bin/grep

ROOT_PATH=/net/icebox/vol/local_images/spins
STREAM_PATH=$ROOT_PATH/7.1

SUN_PLATFORM=`$FIND $STREAM_PATH . -depth -name ShareableEntities | $AWK -F"/" '{if($10 ~ /sun5/) print $0}'`

for i in $SUN_PLATFORM
do
$ECHO $i
$LS $i | $GREP .su | $AWK -F"_" '{print $1}'
done | sort | uniq -c

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sort unique

Hi, I have an input file that I have sorted in a previous stage by $1 and $4. I now need something that will take the first record from each group of data based on the key being $1 Input file 1000AAA|"ZZZ"|"Date"|"1"|"Y"|"ABC"|""|AA 1000AAA|"ZZZ"|"Date"|"2"|"Y"|"ABC"|""|AA... (2 Replies)
Discussion started by: Ads89
2 Replies

2. Shell Programming and Scripting

Sort unique by multiple fields

i need to sort to get all the unique records based on the 1st and 2nd column, and keep the record with the highest value on 5th column if there are duplicates, every column with varies length a^2^x^y^z bxc^2xx2^aa^bvxxxx^cdd a^3^1^2^3 a^2^x^1^c I want a result which will only keep the 1st... (2 Replies)
Discussion started by: dtdt
2 Replies

3. UNIX for Dummies Questions & Answers

Print unique lines without sort or unique

I would like to print unique lines without sort or unique. Unfortunately the server I am working on does not have sort or unique. I have not been able to contact the administrator of the server to ask him to add it for several weeks. (7 Replies)
Discussion started by: cokedude
7 Replies

4. Shell Programming and Scripting

sort split merge -u unique

Hi, this is about sorting a very large file (like 10 gb) to keep lines with unique entries across SOME of the columns. The line originally looked like this: sort -u -k2,2 -k3,3n -k4,4n -k5,5n -k6,6n file_unsorted > file_sorted please note the -u flag. The problem is that this single... (4 Replies)
Discussion started by: jbr950
4 Replies

5. Shell Programming and Scripting

Unique sort with three fields

I have another file with three columns A,B,C as below 123,1,502 123,2,506 123,3,702 234,4,101 235,5,104 456,6,104 456,7,100 i want to sort such that i get a unique value in column A, and for those with multiple value in A, i want the lowest value in C. output should be Code:... (3 Replies)
Discussion started by: dealerso
3 Replies

6. Shell Programming and Scripting

Unique sort with two fields

I have a file with contents below 123,502 123,506 123,702 234,101 235,104 456,104 456,100 i want to sort such that i get a unique value in column A, and for those with multiple value in A, i want the lowest value in B. output should be 123,502 234,101 235,104 456,100 (3 Replies)
Discussion started by: dealerso
3 Replies

7. Shell Programming and Scripting

Awk sort and unique

Input file --------- 12:name1:|host1|host1|host2|host1 13:name2:|host1|host1|host2|host3 14:name3: ...... Required output --------------- 12:name1:host1(2)|host1(1) 13:name2:host1(2)|host2(1)|host3(1) 14:name3: where (x) - Count how many times field appears in last column ... (3 Replies)
Discussion started by: greycells
3 Replies

8. UNIX for Advanced & Expert Users

[Debian, Ethernet, crazy ideas] Data transfer, the hard way...

A little while ago, my PC died. Something critical --- RAM, Mother Board, CPU, not sure. It was old and needed a replacement anyway (I knew it was on its last legs a year ago, but kept putting it off), so I simply ordered a new system. I would like to recover all my old files, however, and... (3 Replies)
Discussion started by: Elric of Grans
3 Replies

9. Shell Programming and Scripting

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... (2 Replies)
Discussion started by: praveenbvarrier
2 Replies

10. Shell Programming and Scripting

Sort and Unique in Perl

Hi, May I know, if a pipe separated File is large, what is the best method to calculate the unique row count of 3rd column and get a list of unique value of the 3rdcolum? Thanks in advance! (20 Replies)
Discussion started by: deepakwins
20 Replies
Login or Register to Ask a Question