DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/)
-   Shell Scripting (http://www.daniweb.com/forums/forum113.html)
-   -   Uniq on certain fields (http://www.daniweb.com/forums/thread123375.html)

sjgriffiths May 9th, 2008 8:47 am
Uniq on certain fields
 
I have the following file

1928282,Stephen LTD,31280938,L34
3128398,Stephen LTD,84327489,L34

I want to uniq on fields 2 & 4, the fields are comma seperated

I cant figure out how to do this....any ideas? im pretty sure uniq does not support this

radoulov May 9th, 2008 10:56 am
Re: Uniq on certain fields
 
Use nawk or /usr/xpg4/bin/awk on Solaris.

awk -F, '!x[$2,$4]++'  input

eggi May 9th, 2008 10:37 pm
Re: Uniq on certain fields
 
You can also use the -u flag to sort, which can pick out fields:

sort -t, -u -k2,2 -k4,4

Best wishes,

Mike


All times are GMT -4. The time now is 5:00 pm.

Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC