Remove duplicate email


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Remove duplicate email
# 1  
Old 11-26-2019
Remove duplicate email

Code:
cat path/to/dir/file.html | grep -i 'x*.com' > path/to/dir/file.txt

Before
xyz.com 
xyz.com

After 
cat path/to/dir/file.html | grep -i 'x*.com' |  sed '$!s/$/,/' | tr -d '\n'> path/to/dir/file.txt

Result --> Preferred
output:
xyz.com, xyz.com

The preferred is the exact output I want, but I want to remove duplicate. I tried sort | uniq but still wont work. Any help appreciated.
# 2  
Old 11-26-2019
how about (for starters):
Code:
awk -v str='x*.com' '$1~str && !a[$1]++' myFile

This User Gave Thanks to vgersh99 For This Post:
# 3  
Old 11-26-2019
Sorry still show duplicate
# 4  
Old 11-26-2019
myFile:
Code:
xyz.com
xyz.com
1xyz.com
123.com

Code:
$ awk -v str='x*.com' '$1~str && !a[$1]++' myFile
xyz.com
1xyz.com
123.com

# 5  
Old 11-26-2019
I need them to be on the same line with comma seperated as it appears in my preferred output.
# 6  
Old 11-27-2019
Your grep seems not precise, perhaps you mean grep -i '^x.*\.com$' (starts with an x then any amount of characters then .com at the end)
A sed 's/$/,/' does not delete $ because it is an anchor - not a character. But after an N command (that appends the following line to the input buffer) one can remove the embedded \n character.
The following works on all Unix-like OS:
Code:
grep -i '^x.*\.com$' file.html | sed -e ':L' -e '$!N;s/\n/, /;tL'

# 7  
Old 12-02-2019
This removes the emails that are the same. I need to only remove the duplicates
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove duplicate records

Hi, i am working on a script that would remove records or lines in a flat file. The only difference in the file is the "NOT NULL" word. Please see below example of the input file. INPUT FILE:> CREATE a ( TRIAL_CLIENT NOT NULL VARCHAR2(60), TRIAL_FUND NOT NULL... (3 Replies)
Discussion started by: reignangel2003
3 Replies

2. UNIX for Dummies Questions & Answers

Remove duplicate

Hi, How can I replace || with space and then remove duplicate from following text? T111||T222||T444||T222||T555 Thanks in advance (10 Replies)
Discussion started by: tinku981
10 Replies

3. Shell Programming and Scripting

Remove duplicate

Hi , I have a pipe seperated file repo.psv where i need to remove duplicates based on the 1st column only. Can anyone help with a Unix script ? Input: 15277105||Common Stick|ESHR||Common Stock|CYRO AB 15277105||Common Stick|ESHR||Common Stock|CYRO AB 16111278||Common Stick|ESHR||Common... (12 Replies)
Discussion started by: samrat dutta
12 Replies

4. Shell Programming and Scripting

How to remove duplicate ID's?

HI I have file contains 1000'f of duplicate id's with (upper and lower first character) as below i/p: a411532A411532a508661A508661c411532C411532 Requirement: But i need to ignore lowercase id's and need only below id's o/p: A411532 A508661 C411532 (9 Replies)
Discussion started by: buzzme
9 Replies

5. Shell Programming and Scripting

remove duplicate

Hi, I am tryung to use shell or perl to remove duplicate characters for example , if I have " I love google" it will become I love ggle" or even "I loveggle" if removing duplicate white space Thanks CC (6 Replies)
Discussion started by: ccp
6 Replies

6. UNIX for Dummies Questions & Answers

Remove duplicate in array

Hi, I have a list of numbers stored in an array as below. 5 7 10 30 30 40 50 Please advise how could I remove the duplicate value in the array ? Thanks in advance. (5 Replies)
Discussion started by: Rock
5 Replies

7. Shell Programming and Scripting

Remove duplicate text

Hello, I have a log file which is generated by a script which looks like this: userid: 7 starttime: Sat May 24 23:24:13 CEST 2008 endtime: Sat May 24 23:26:57 CEST 2008 total time spent: 2.73072 minutes / 163.843 seconds date: Sat Jun 7 16:09:03 CEST 2008 userid: 8 starttime: Sun May... (7 Replies)
Discussion started by: dejavu88
7 Replies

8. Shell Programming and Scripting

Remove duplicate

Hi all, I have a text file fileA.txt DXRV|02/28/2006 11:36:49.049|SAC||||CDxAcct=2420991350 DXRV|02/28/2006 11:37:06.404|SAC||||CDxAcct=6070970034 DXRV|02/28/2006 11:37:25.740|SAC||||CDxAcct=2420991350 DXRV|02/28/2006 11:38:32.633|SAC||||CDxAcct=6070970034 DXRV|02/28/2006... (2 Replies)
Discussion started by: sabercats
2 Replies

9. Shell Programming and Scripting

Remove duplicate ???

Hi all, I have a out.log file CARR|02/26/2006 10:58:30.107|CDxAcct=1405157051 CARR|02/26/2006 11:11:30.107|CDxAcct=1405157051 CARR|02/26/2006 11:18:30.107|CDxAcct=7659579782 CARR|02/26/2006 11:28:30.107|CDxAcct=9534922327 CARR|02/26/2006 11:38:30.107|CDxAcct=9534922327 CARR|02/26/2006... (3 Replies)
Discussion started by: sabercats
3 Replies

10. Shell Programming and Scripting

remove duplicate

i have a text its contain many record, but its written in one line, i want to remove from that line the duplicate record, not record have fixed width ex: width = 4 inputfile test.txt =abc cdf abc abc cdf fgh fgh abc abc i want the outputfile =abc cdf fgh only those records can any one help... (4 Replies)
Discussion started by: kazanoova2
4 Replies
Login or Register to Ask a Question