LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-27-2022, 10:04 AM   #1
rpartee1
LQ Newbie
 
Registered: Mar 2022
Posts: 4

Rep: Reputation: 0
I wrote code to remove duplicate lines: I keep getting the same error message, help?


My code is this:

sed -n 'G;s/\n/&&/;/^\([ -~]*\n\).*\n\1/d;s/\n//; h; P' out.txt > out2.txt

I keep getting the error message.
sed: -e expression #2, char 50: Unmatched ( or \(

Can you tell me what I am doing wrong ?
 
Old 03-27-2022, 10:12 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,753

Rep: Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983
Quote:
Originally Posted by rpartee1 View Post
My code is this:
Code:
sed -n 'G;s/\n/&&/;/^\([ -~]*\n\).*\n\1/d;s/\n//; h; P' out.txt > out2.txt
I keep getting the error message.
sed: -e expression #2, char 50: Unmatched ( or \(

Can you tell me what I am doing wrong ?
You never bothered to go back to your other two threads to respond or show your effort, and you are now trying to take credit for something someone else wrote:
https://edoras.sdsu.edu/doc/sed-oneliners.html

May want to copy/paste the exact command with the proper spacing. Also may want to look at the uniq command, and try a further Internet search for "how to remove duplicate lines in linux".
 
3 members found this post helpful.
Old 03-27-2022, 10:42 AM   #3
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,249

Rep: Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323
Why don't you just use uniq?
 
2 members found this post helpful.
Old 03-27-2022, 11:36 AM   #4
rpartee1
LQ Newbie
 
Registered: Mar 2022
Posts: 4

Original Poster
Rep: Reputation: 0
Can I use:
$sort out.txt | uniq -u > out2.txt

to replace:
sed -n 'G;s/\n/&&/;/^\([ -~]*\n\).*\n\1/d;s/\n//; h; P' out.txt > out2.txt
 
Old 03-27-2022, 12:12 PM   #5
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931
Quote:
Originally Posted by rpartee1 View Post
Can I use:
$sort out.txt | uniq -u > out2.txt

to replace:
sed -n 'G;s/\n/&&/;/^\([ -~]*\n\).*\n\1/d;s/\n//; h; P' out.txt > out2.txt
You should know the answer.

Don't you have a test input file or two and know how the output should be modified?

Try your term out. It will remove duplicates and sort the file, but you should test to determine if it does exactly what you wanted for a result.
 
2 members found this post helpful.
Old 03-27-2022, 01:40 PM   #6
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,880
Blog Entries: 1

Rep: Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871Reputation: 1871
@OP As a start please learn how to use [code] and [/code] tags.
 
2 members found this post helpful.
Old 03-27-2022, 02:09 PM   #7
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,753

Rep: Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983Reputation: 7983
Quote:
Originally Posted by rpartee1 View Post
Can I use:
Code:
$sort out.txt | uniq -u > out2.txt
to replace:
Code:
sed -n 'G;s/\n/&&/;/^\([ -~]*\n\).*\n\1/d;s/\n//; h; P' out.txt > out2.txt
Why don't you try it and find out??? And again, you aren't even acknowledging your first two posts, where you just ask someone to do your homework for you, nor are you acknowledging the fact you have been caught claiming that 'you' wrote the above sed statement. You have been told about the uniq statement at least three times.

You also don't seem to want to respond to the advice to look in your textbook, or show what you have personally done/tried. Again, we are happy to HELP you, but we aren't going to do everything FOR YOU.
 
3 members found this post helpful.
Old 03-27-2022, 10:33 PM   #8
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,011

Rep: Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194Reputation: 3194
Also awk can do this with an unsorted list and redirection:
Code:
awk '!_[$0]++' in_file > out_file
 
1 members found this post helpful.
Old 03-28-2022, 06:32 AM   #9
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,039

Rep: Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347
Quote:
Originally Posted by rpartee1 View Post
Can I use:
$sort out.txt | uniq -u > out2.txt

to replace:
sed -n 'G;s/\n/&&/;/^\([ -~]*\n\).*\n\1/d;s/\n//; h; P' out.txt > out2.txt
No, you will never get the same error message from sort.
Otherwise
Code:
sort -u input > output
 
  


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
LXer: How To Empty a File, Delete N Lines From a File, Remove Matching String From a File, And Remove Empty/Blank Lines From a File In Linux LXer Syndicated Linux News 0 11-22-2017 12:30 PM
LXer: Amazon wrote a new TLS crypto library in just 6,000 lines of code LXer Syndicated Linux News 0 07-01-2015 10:33 PM
[SOLVED] what do these lines wrote in C might mean? Gerwar Programming 2 03-12-2011 12:22 PM
Evolution - How can I remove the "On [date] [person] wrote:" message? jsteel Linux - General 2 03-24-2010 03:47 AM
Delete Duplicate Lines in a file, leaving only the unique lines left xmrkite Linux - Software 6 01-14-2010 06:18 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:32 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