LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-18-2021, 01:48 PM   #1
angel115
Member
 
Registered: Jul 2005
Location: France / Ireland
Distribution: Debian mainly, and Ubuntu
Posts: 542

Rep: Reputation: 79
SED print matching line


Hi,

I need to print all word from a file containing "e" or "é" and followed by 2 identical consonant
I've tried the following but it doesn't return the right result (although the regex work fine in regex101.com)

Code:
sed -E '/[eé](b{2}|c{2}|d{2}|f{2}|g{2}|h{2}|j{2}|k{2}|l{2}|m{2}|n{2}|p{2}|q{2}|r{2}|s{2}|t{2}|u{2}|v{2}|w{2}|x{2}|z{2})/p' adjectives.txt
I'm test my code against this file

Thanks for your help
 
Old 02-18-2021, 01:57 PM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,876

Rep: Reputation: 7315Reputation: 7315Reputation: 7315Reputation: 7315Reputation: 7315Reputation: 7315Reputation: 7315Reputation: 7315Reputation: 7315Reputation: 7315Reputation: 7315
probably you need sed -n
 
1 members found this post helpful.
Old 02-18-2021, 02:04 PM   #3
angel115
Member
 
Registered: Jul 2005
Location: France / Ireland
Distribution: Debian mainly, and Ubuntu
Posts: 542

Original Poster
Rep: Reputation: 79
Quote:
Originally Posted by pan64 View Post
probably you need sed -n
Silly me. Yes of course.

I think I need some sleep.

Thanks a lot
 
Old 02-18-2021, 02:06 PM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,876

Rep: Reputation: 7315Reputation: 7315Reputation: 7315Reputation: 7315Reputation: 7315Reputation: 7315Reputation: 7315Reputation: 7315Reputation: 7315Reputation: 7315Reputation: 7315
you are welcome
If you really want to say thanks just click on yes.
If your problem is solved please mark the thread solved.
 
Old 02-18-2021, 02:12 PM   #5
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
I'd rewrite this as
Code:
sed -En '/[eé]([bcdfghj-np-tvwxz])\1/p' adjectives.txt

Last edited by shruggy; 02-18-2021 at 02:14 PM.
 
Old 02-18-2021, 02:13 PM   #6
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,313
Blog Entries: 3

Rep: Reputation: 3723Reputation: 3723Reputation: 3723Reputation: 3723Reputation: 3723Reputation: 3723Reputation: 3723Reputation: 3723Reputation: 3723Reputation: 3723Reputation: 3723
It's also possible to shorten the pattern a bit,

Code:
sed -rne '/[eé]([bcdfghjklmnpqrstvwxz])\1/p'
 
Old 02-18-2021, 03:32 PM   #7
boughtonp
Senior Member
 
Registered: Feb 2007
Location: UK
Distribution: Debian
Posts: 3,605

Rep: Reputation: 2548Reputation: 2548Reputation: 2548Reputation: 2548Reputation: 2548Reputation: 2548Reputation: 2548Reputation: 2548Reputation: 2548Reputation: 2548Reputation: 2548

An even shorter pattern, which also makes the vowel-exclusion more obvious, can be achieved using a negative lookahead in Perl/grep:
Code:
grep -P '[eé]((?![eiou])[b-z])\1' adjectives.txt

Last edited by boughtonp; 02-18-2021 at 03:33 PM.
 
2 members found this post helpful.
Old 02-18-2021, 05:30 PM   #8
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,799

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
Perhaps your locale allows an equivalence class [=e=] ?
And certainly you can have a character class of consonants, in a (capture group) followed by its \1 reference --> repetition
Code:
sed -n -E '/[=e=]([bcdfghjklmnpqrstvwxz])\1/p'
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
SED one-liner for remove or comment out a line matching a certain pattern after the first line match Honest Abe Linux - Newbie 8 10-04-2018 05:36 AM
Find/grep command to find matching files, print filename, then print matching content stefanlasiewski Programming 9 06-30-2016 05:30 PM
[SOLVED] sed command for matching the end character of a line and replacing the whole line. mamunm Linux - Newbie 4 04-12-2014 12:19 AM
sed and regexp matching (GNU sed version 4.2.1) Ashkhan Programming 8 02-27-2012 09:12 AM
SED - Delete line above or below as well as matching line... OldGaf Programming 7 06-26-2008 11:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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