How to get value


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to get value
# 1  
Old 03-25-2009
How to get value

Guys,
I have a file which have two columns as follows: as you can see that the second column has repeated values.
8095;8082
8097;8082
8062;8083
8083;8083
8072;8085
8073;8085
8074;8085
8075;8085
8079;8085
8085;8085
8086;8085
8087;
8085
4400;8090
8090;8090

So what I need is to have the repeated values once with the all values in the first columns against it. e.g. The value in the second column "8082" have to values in the first column which is 8095, 8097.
how to do it guys please advice?????
# 2  
Old 03-25-2009
Use gawk, nawk or /usr/xpg4/bin/awk on Solaris:

Code:
awk -F\; 'END { for (k in _) print k FS _[k] }
{ _[$2] = _[$2] ? _[$2] FS $1 : $1 }' infile

# 3  
Old 03-27-2009
Code:
nawk -F";" '{
        _[$2]=sprintf("%s,%s",_[$2],$1)
        }
        END{
        for(i in _)
        print i""_[i]
        }' filename

Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question