LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 04-10-2017, 01:26 AM   #16
MBoyle19
LQ Newbie
 
Registered: Apr 2017
Posts: 10

Original Poster
Rep: Reputation: Disabled

Quote:
Originally Posted by pan64 View Post
glad to help you
if you really want to say thanks just click on yes

And this is the case when you do not need (but in general yes, you have to use quotes).

grep knows 3 different kind of regex, sed knows at least 2, awk has its own style, but more or less similar....
perl has its own PCRE and python knows that too.
Just clicked on yes

Quote:
Originally Posted by Turbocapitalist View Post
syg00 mentioned them above in #2 and #4. They are perl regular expressions, ported to other languages this is often called perl-compatible regular expression (PCRE). Within perl they are properly called metasymbols and they stand in for some functionality as well as pattern data. You'll find PCRE nearly everywhere these days.

But as to whether sed and awk can understand perl's regular expression metasymbols, the answer is, "no" at least for existing versions to-date.

If you find them useful, then you can get a lot out of one-liners in perl. See the options -e, -i, -n, and -p in
Code:
man perlrun
Anything you can do with sed and awk you can do, plus more, in perl.
Regex is complex. I read online on it's usage and some stuff is still Greek to me. To learn another language like perl is going to give me a brain meltdown. Maybe I give it a quick look some day

Last edited by MBoyle19; 04-10-2017 at 01:27 AM.
 
Old 04-10-2017, 01:33 AM   #17
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 5,607
Blog Entries: 3

Rep: Reputation: 2851Reputation: 2851Reputation: 2851Reputation: 2851Reputation: 2851Reputation: 2851Reputation: 2851Reputation: 2851Reputation: 2851Reputation: 2851Reputation: 2851
You don't have to learn it all at once, just like you don't have to learn the languages sed and awk all at once either. Here you can use it like beginning-level sed:

Code:
perl -p -e 's/\w+/blah/;' < inputfile.txt > outputfile.txt

perl -p -i.bak -e 's/\w+/blah/;' *.txt
Those formulas will allow you to do basic sed-like substitution but with full perl regular expressions including your full range of metasymbols and special variables.
 
1 members found this post helpful.
Old 04-10-2017, 01:34 AM   #18
MBoyle19
LQ Newbie
 
Registered: Apr 2017
Posts: 10

Original Poster
Rep: Reputation: Disabled
Thank you all! I clicked on yes for helpful answers to ALL members here
 
Old 04-10-2017, 01:47 AM   #19
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 16,482

Rep: Reputation: 5530Reputation: 5530Reputation: 5530Reputation: 5530Reputation: 5530Reputation: 5530Reputation: 5530Reputation: 5530Reputation: 5530Reputation: 5530Reputation: 5530
and actually there are online regex testers available: http://www.myezapp.com/apps/dev/regexp/show.ws or http://www.regextester.com/
 
1 members found this post helpful.
Old 04-10-2017, 01:54 AM   #20
MBoyle19
LQ Newbie
 
Registered: Apr 2017
Posts: 10

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Turbocapitalist View Post
You don't have to learn it all at once, just like you don't have to learn the languages sed and awk all at once either. Here you can use it like beginning-level sed:

Code:
perl -p -e 's/\w+/blah/;' < inputfile.txt > outputfile.txt

perl -p -i.bak -e 's/\w+/blah/;' *.txt
Those formulas will allow you to do basic sed-like substitution but with full perl regular expressions including your full range of metasymbols and special variables.
Quote:
Originally Posted by pan64 View Post
and actually there are online regex testers available: http://www.myezapp.com/apps/dev/regexp/show.ws or http://www.regextester.com/
and a
 
Old 04-10-2017, 05:54 AM   #21
TobyV
LQ Newbie
 
Registered: Apr 2017
Posts: 19

Rep: Reputation: Disabled
Quote:
Originally Posted by MBoyle19 View Post
Can sed and awk understand shorthand regex?
sed can use shorthand or extended regex with the -r switch. Don't know about awk.

For example, I want to pad a zero to the number 1 and not 3 using the \b word boundary.

Code:
echo track 1 of 3 | sed -r 's/\b[[:digit:]]\b/0&/'
track 01 of 3
Below is the gnu-style regex for word boundary
Code:
echo track 1 of 3 | sed 's/\<[[:digit:]]\>/0&/'
track 01 of 3
The [:digit:] is called a class set, It is equivalent to [0-9]

Last edited by TobyV; 04-10-2017 at 05:55 AM.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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] trouble with a grep regex r.stiltskin Programming 9 01-04-2015 05:45 PM
[SOLVED] RegEx in grep confusion... mddnix Linux - Newbie 11 05-26-2013 07:07 PM
REGEX with grep Anna1987 Linux - Newbie 9 03-09-2013 07:56 AM
grep regex with wildcard yknot7 Linux - Newbie 6 11-10-2011 01:11 AM
regex in ls vs. grep jhwilliams Linux - Software 2 08-10-2007 10:14 PM

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

All times are GMT -5. The time now is 05:46 AM.

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