-   Linux - Newbie (
-   -   sort and uniq conundrum (

BFCsaus 03-29-2012 12:02 PM

sort and uniq conundrum

Apologies for posting what should be a very simple task but hopefully someone can give me the correct command to sort uniquely from the 1st word in the file. ie.

The file would say for example:

hostname1 17/08/10
hostname1 18/08/10
hostname1 19/08/10
hostname1 20/08/10
hostname2 17/08/10
hostname2 18/08/10
hostname2 19/08/10
hostname2 20/08/10

So after the sort I simply have:

hostname1 17/08/10
hostname2 17/08/10


bigrigdriver 03-29-2012 12:32 PM

Grep is the tool use. Lets say the data is in a file named dates.txt. To use grep to find the records with the date 17/08/10, the grep command would be:

grep "17/08/10" dates.txt

chrism01 03-29-2012 07:43 PM


sort -u -k1,1 <filename>

# output ...
hostname1 17/08/10
hostname2 17/08/10

arn2025 03-30-2012 03:13 AM

i think this would help


sort output.txt | grep 17

BFCsaus 03-30-2012 05:08 AM

Thanks Chris, sort -u -k1,1 <filename> worked...

Also works on a CSV file (with -t) which is the next job...


All times are GMT -5. The time now is 11:29 PM.