LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 07-01-2018, 12:10 PM   #1
arun natarajan
Member
 
Registered: Jun 2014
Posts: 111

Rep: Reputation: Disabled
uniq command not working with comma as delimiter


Hi,

Am trying to remove the duplicate records based on field wise.
But uniq command work only when fields are delimited by space ' '.
How to work on uniq command, when fields are delimited by comma , or another separators ?

Tom,Westley,Essex
Tom,Westley,Essex
Ravi,Bopara,Essex
Marcus,Trescothick,Somerset
Joe,Root,Yorkshire
Jonny,Bairstow,Yorkshire
 
Old 07-01-2018, 01:38 PM   #2
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Change the delimiters in the input file to space before passing to uniq.
Code:
sed 's/,/ /g' | uniq <options>  filename
You didn't share what you were using the delimiter for, so I can't guess at which option(s) you need.

Also see sort -u in
Code:
man sort
 
Old 07-01-2018, 01:44 PM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,312
Blog Entries: 3

Rep: Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722
You can probably do it all in sort. Pay attention to the -t, -k, and -u options. See "man sort"

Also, please say more about what you are trying to do. Show an example of what you want the results to look like from the input you have provided above.
 
1 members found this post helpful.
Old 07-01-2018, 02:40 PM   #4
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by arun natarajan View Post
Hi,
Am trying to remove the duplicate records based on field wise. But uniq command work only when fields are delimited by space ' '. How to work on uniq command, when fields are delimited by comma , or another separators ?

Tom,Westley,Essex
Tom,Westley,Essex
Ravi,Bopara,Essex
Marcus,Trescothick,Somerset
Joe,Root,Yorkshire
Jonny,Bairstow,Yorkshire
Sounds familiar...much in line with other *VERY* similar questions in the past, which show no effort on your part, many of which even involve how to sort and use uniq
https://www.linuxquestions.org/quest...rt-4175596519/
https://www.linuxquestions.org/quest...pt-4175597362/
https://www.linuxquestions.org/quest...ze-4175598565/
https://www.linuxquestions.org/quest...te-4175594480/
https://www.linuxquestions.org/quest...es-4175588761/

Is there some point where you're going to read the "Question Guidelines", and show your own efforts??? You've been here some time now....
 
Old 07-03-2018, 01:58 PM   #5
arun natarajan
Member
 
Registered: Jun 2014
Posts: 111

Original Poster
Rep: Reputation: Disabled
hi tbone,

i hope this question is unique when compared to others and here am trying the options only in "uniq" command and not in any other commands, to understand how "uniq" is effective when compared to others.
 
Old 07-03-2018, 02:04 PM   #6
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,312
Blog Entries: 3

Rep: Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722
Properly designed utilities work together. uniq needs sorted data and sort has quite a few supplemental capabilities and the two utilities compliment each other.

Show some examples of what you have been trying and explain more specifically what results you want, including examples.
 
Old 07-03-2018, 03:06 PM   #7
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by arun natarajan View Post
hi tbone,
i hope this question is unique when compared to others and here am trying the options only in "uniq" command and not in any other commands, to understand how "uniq" is effective when compared to others.
No, it is not; it is use of the same tool in a slightly different manner. And again, you have shown no efforts of your own. You have done very similar things in the past, and have also asked for handouts in those threads as well.

We are happy to HELP you, but asking us to write your scripts is another thing. Also, you need to start thinking about and APPLYING what you are told, so you can learn how to accomplish these things. You have all the answers and information you need, based on your other threads. It is now up to YOU to do the work.
 
Old 07-04-2018, 06:14 AM   #8
arun natarajan
Member
 
Registered: Jun 2014
Posts: 111

Original Poster
Rep: Reputation: Disabled
Ok got it, thanks
 
Old 07-04-2018, 08:49 AM   #9
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,636

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by arun natarajan View Post
Ok got it, thanks
Great...but you've stated such things in the past as well. So can you now show us your own efforts, so we can try to help you??? Reference any of the other threads where you ask about uniq and other commands in scripts if you need help.
 
  


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
uniq command question barakolshe Linux - Newbie 1 06-30-2017 07:18 PM
[SOLVED] uniq command not able to remove duplicate entries ls_milkyway Linux - Newbie 8 08-22-2013 05:18 AM
[SOLVED] AWK / SED - Parsing a CSV file with comma delimiter, and some extra needs. PenguinJr Programming 8 05-24-2011 06:28 PM
uniq command help jcky Linux - Newbie 1 11-17-2009 09:28 AM
How to delete Comma in a comma separated file with double quotes as quote character pklcnu Linux - Newbie 2 03-24-2009 05:50 PM

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

All times are GMT -5. The time now is 02:01 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
Open Source Consulting | Domain Registration