LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 11:02 AM   #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, 11:32 AM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
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, 06:43 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,356

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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, 02: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, 04: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



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 10:12 AM
history |tr '\011' ' ' |tr -s " "| cut -d' ' -f3 |sort |uniq -c |sort -nbr |head -n10 alan_ri General 12 12-04-2010 09:01 PM
[SOLVED] bash - merging strings (perhaps with sort | uniq) cmbouchard Linux - Newbie 4 11-16-2010 11:21 PM
Is there a sort of 2nd SSH daemon server, sort of JAILKIT, in the debian repositories frenchn00b Debian 5 06-20-2010 04:03 AM
sort & uniq tostay2003 Programming 3 06-28-2008 06:14 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:54 AM.

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
Open Source Consulting | Domain Registration