Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

unique values

Status
Not open for further replies.

sandeepmur

Programmer
Dec 14, 2003
295
PT
Hi,

I am trying to obtain unique values from a file like this:

$> uniq abc.xls > test.xls

but the above does not seem to be working.. I also tried using the -u option to no avail..

is there any other alternative ??

thnx
 
The only criteria that I see with the command uniq is the repeated lines must be adjacent to each other. You also do not need the > between the file names... In your example, the command should look like:

uniq abc.xls test.xls
 
I am doing something like this:

netstat | grep tcp | awk -f awkscript.awk > abc.xls
uniq abc.xls >> netstat.xls
cp netstat.xls temp.xls
rm netstat.xls
uniq temp.xls > netstat.xls
rm temp.xls
rm abc.xls


Even if I remove the ">" in the uniq command, it doesnt make any difference..

any further ideias ??
thnx
 
Code:
netstat | grep tcp | ( awk -f awkscript.awk; cat netstat.xls) | sort | uniq > netstat.xls

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
ooops,
nevermind the above - this is wrong
not tested:
Code:
( (netstat | grep tcp | awk -f awkscript.awk) ; cat netstat.xls ) | sort | uniq > netstat.xls

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
In the sort man page take a look at the -k and -u options.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
My problem is that apart from the fact that I want the file netstat.xls to contain only unique values, I am putting the code above as a shell script which is executed every hour and appends to netstat.xls only unique values which are not already present in the file..

changing ">" to ">>" simply appends the file without caring for unique values..

thnx
 
netstat | grep tcp | awk -f awkscript.awk > abc.xls
sort -o netstat.xls -u abc.xls netstat.xls

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hi,

Thanks for the response.. Let me see if I got the above right..

netstat | grep tcp | awk -f awkscript.awk > abc.xls
wud create a file abc.xls with the output from the netstat command.

Code:
sort -o netstat.xls -u abc.xls netstat.xls
I am not sure why -o option is needed when -u abc.xls netstat.xls wud probably do the same thing..

could you please explain the above ? also, will this actually append the file netstat.xls when there is new data ?

Since the file generated is very difficult to validade manually owing to large number of connections, I need to be certain that it works fine..

thnx in adv,
 
man sort (as already suggested)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top