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 05-26-2019, 12:43 PM   #1
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240

Rep: Reputation: 103Reputation: 103
regex if conditionals - grep: nothing to repeat


Code:
grep "^Subject:" emaillist.mbox
Subject: Project-specific sitemap for build server content
Subject: Re: Project-specific sitemap for build server content
Subject: [Hosting] ns2.osuosl.org maintenance - June 11,
grep "^From:" emaillist.mbox
From: Ken <k23423@ethercloud.io>
From: Gavin <g23432423@ethercloud.io>
From: Music <m23423423@ethercloud.io>
And I'm trying this to match the From and Subject lines:
Code:
grep -Po '((?<subj>Subject)|(?<from>From)): (?(subj).+|?(from)\w+? <\w+?@\w+?\.\w{1,63}>)' emaillist.mbox
grep: nothing to repeat
I'm not sure exactly what I'm doing wrong.

Last edited by vincix; 05-26-2019 at 12:45 PM.
 
Old 05-26-2019, 12:46 PM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
I don't understand what do you want to achieve, but you can definitely try: https://regex101.com/
 
1 members found this post helpful.
Old 05-26-2019, 01:00 PM   #3
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240

Original Poster
Rep: Reputation: 103Reputation: 103
I'm simply testing if conditionals on a file, that is to say, only display lines beginning with "From" and lines beginning with "Subject" and the string that follows. For "Subject: " it would be anything, for "From: " I'd match the format that can be found in the lines themselves: string <email@format.com>

Indeed, testing it on the site showed me what the problem was. It didn't like the |? because I have to place a bracket before it as in (?
So the correct way seems to be:
Code:
((?<subj>Subject)|(?<from>From)): (?(subj).+|(?(from)\w+? <\w+?@\w+?\.\w{1,63})>)
So nothing to repeat meant that I was trying to associate ? with a pipe, which didn't make sense, of course.

Last edited by vincix; 05-26-2019 at 01:01 PM.
 
  


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] regex conditionals - conditional group contains more than two branches vincix Programming 1 05-24-2019 07:57 PM
[SOLVED] differences between shell regex and php regex and perl regex and javascript and mysql golden_boy615 Linux - General 2 04-19-2011 01:10 AM
[SOLVED] Problem with BASH conditionals - passing condition as variable smaddox Programming 8 09-18-2009 11:21 AM
configure (automake) conditionals kev000 Programming 0 07-15-2007 12:25 PM
bash scripting - conditionals dguy Linux - Newbie 4 01-19-2002 08:00 AM

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

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