Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum. |
| Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
08-01-2007, 11:47 AM
|
#1
|
|
Senior Member
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,167
|
sed: howto group regex's into AND/OR clauses?
OR and AND are hard to google for...
Is there anyway to change something like:
Code:
echo "one two three four" | \
sed "s/regex_for_one/substitution_string/" | \
sed "s/regex_for_two/substitution_string/" | \
sed "s/regex_for_three/substitution_string/" | \
sed "s/regex_for_four/substitution_string/"
into something like this...
Code:
echo "one two three four" | \
sed "s/regex_for_one OR regex_for_two OR regex_for_three OR regex_for_four/substitution_string/"
This is a question about syntax, basically. How do I combine regular expressions into and/or groups, given that the above capitalized OR's doesn't work?
|
|
|
|
08-01-2007, 12:40 PM
|
#2
|
|
Senior Member
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,476
|
Code:
alucard@organa:~$ echo "one two three four" | sed -r "s/(one|two|three|four)/five/g"
five five five five
-r for "extended regular expressions"; (A|B) meaning A OR B
|
|
|
|
08-01-2007, 01:00 PM
|
#3
|
|
Member
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 714
Rep:
|
Hi.
This single sed invocation in this script:
Code:
#!/bin/sh
# @(#) s1 Demonstrate sed substitution.
set -o nounset
echo
echo "GNU bash $BASH_VERSION" >&2
sed --version | head -1 >&2
echo
echo "one two three four" |
sed \
-e "s/one/ONE/" \
-e "s/two/TWO/" \
-e "s/three/THREE/" \
-e "s/four/FOUR/"
exit 0
produces:
Code:
% ./s1
GNU bash 2.05b.0(1)-release
GNU sed version 4.1.2
ONE TWO THREE FOUR
If this is not what you had in mind, please explain more ... cheers, makyo
|
|
|
|
08-01-2007, 01:02 PM
|
#4
|
|
Senior Member
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,167
Original Poster
|
Ah yes. That would make good sense, indeed. Thanks!
|
|
|
|
08-01-2007, 01:05 PM
|
#5
|
|
Member
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 714
Rep:
|
Hi.
I think AlucardZero understood better than I did ... cheers, makyo
|
|
|
|
08-01-2007, 02:19 PM
|
#6
|
|
Senior Member
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,167
Original Poster
|
Quote:
Hi.
I think AlucardZero understood better than I did ... cheers, makyo
|
Yes, I believe so - it is hard to ask understandable questions! Thank you for the help, anyhow.
- Jhwilliams
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 01:48 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|