LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 04-01-2009, 12:05 PM   #16
shahgols
Member
 
Registered: Dec 2006
Posts: 97

Original Poster
Rep: Reputation: 15

Quote:
Originally Posted by Robhogg View Post
I know what you mean - I often refer to these patterns as an explosion in a punctuation factory. They are called regular expressions, and consist of literal characters and metacharacters. The pattern means:
Code:
!             Delimiter beginning search pattern
\(<h1>\)      Group 1: literal <h1>
\(<a[^>]*>\)  Group 2: <a then 0 or more characters that are not >'s, then >
\([^<]*\)     Group 3: Any number of characters that are not <'s
\(</a>\)      Group 4: literal </a>
\(</h1>\)     Group 5: literal </h1>
!             End of search pattern, beginning of replace pattern
\1            Replay group 1
\3            Replay group 3
\5            Replay group 5
!             End of replace pattern
Some stuff on sed and regular expressions from the Linux documentation project.

The reason you got the error message is that you used single quotes - '...' - rather than backticks -`...` around the ls command in the first line - very easy to do. Backticks are on the key to the left of the 1 on a US/UK keyboard, but I would tend to use $(ls *.html) - the $(...) does the same thing as the backticks, but is a lot easier to read.

Edited to add: slight warning about the documentation on regular expressions - there are different forms. For instance, in the link above, it tells you prentheses -- ( ) -- enclose a group. However, in the sed version, escaped parentheses - \( \) - are used.
Rob, I have to thank you again for the explanation above, it all makes sense now. Thank you.
 
Old 04-02-2009, 07:07 AM   #17
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,226

Rep: Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022Reputation: 2022
Just a small fyi; each lang that processes 'regexes' uses an internal 'regex engine'. However, each regex engine tends to be different to other regex engines, to a larger or smaller degree.
See for example http://regex.info/
IOW, regex 'incantations' may or may not(!) be transferable... YHBW...
 
Old 04-02-2009, 02:32 PM   #18
Robhogg
Member
 
Registered: Sep 2004
Location: Old York, North Yorks.
Distribution: Debian 7 (mainly)
Posts: 653

Rep: Reputation: 85
Quote:
Originally Posted by shahgols View Post
Wow, thank you so much Rob for helping me learn this stuff.
No problem - "glad to be of service!", as a Sirius Cybernetics Corporation door might say
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
when to quote or not to quote variable names - mktemp problem glinux Linux - Newbie 3 02-20-2009 04:37 PM
Price quote... jsm Linux - General 2 11-08-2006 02:20 PM
Boot Quote? liquidrabbit Slackware 3 04-10-2006 05:37 PM
Quote 1 gb to 1 user? itz2000 Linux - Newbie 5 02-19-2006 02:30 PM
quote tundra General 2 09-21-2002 05:58 AM


All times are GMT -5. The time now is 07:40 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration