LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   sort and uniq conundrum (https://www.linuxquestions.org/questions/linux-newbie-8/sort-and-uniq-conundrum-937106/)

BFCsaus 03-29-2012 12:02 PM

sort and uniq conundrum
 
Hi,

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


Thanks.

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:
Code:

grep "17/08/10" dates.txt

chrism01 03-29-2012 07:43 PM

Code:

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

Code:

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...


Cheers!!


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