LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-29-2012, 12:02 PM   #1
BFCsaus
Member
 
Registered: Jan 2007
Posts: 36

Rep: Reputation: 15
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.
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 03-29-2012, 12:32 PM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian Jessie 8.4
Posts: 5,873

Rep: Reputation: 348Reputation: 348Reputation: 348Reputation: 348
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
 
Old 03-29-2012, 07:43 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Code:
sort -u -k1,1 <filename>

# output ...
hostname1 17/08/10
hostname2 17/08/10
 
2 members found this post helpful.
Old 03-30-2012, 03:13 AM   #4
arn2025
LQ Newbie
 
Registered: Feb 2012
Posts: 26
Blog Entries: 1

Rep: Reputation: Disabled
i think this would help

Code:
sort output.txt | grep 17
 
Old 03-30-2012, 05:08 AM   #5
BFCsaus
Member
 
Registered: Jan 2007
Posts: 36

Original Poster
Rep: Reputation: 15
Thanks Chris, sort -u -k1,1 <filename> worked...

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


Cheers!!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] using sort and uniq in bash bibiki Linux - Newbie 2 02-19-2011 11:12 AM
history |tr '\011' ' ' |tr -s " "| cut -d' ' -f3 |sort |uniq -c |sort -nbr |head -n10 alan_ri General 12 12-04-2010 10:01 PM
[SOLVED] bash - merging strings (perhaps with sort | uniq) cmbouchard Linux - Newbie 4 11-17-2010 12:21 AM
Is there a sort of 2nd SSH daemon server, sort of JAILKIT, in the debian repositories frenchn00b Debian 5 06-20-2010 05:03 AM
sort & uniq tostay2003 Programming 3 06-28-2008 07:14 PM


All times are GMT -5. The time now is 08:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration