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 |
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. |
|
 |
03-10-2012, 09:23 PM
|
#1
|
|
Member
Registered: Aug 2010
Location: Zhongli, Taoyuan
Distribution: slackware, windows, debian (armv4l GNU/Linux)
Posts: 404
Rep:
|
regex text
Hi, sorry again, I am trying to match text using sed:
Code:
/topics/view/246126_text.html
/topics/view/5251_var.html
/topics/view/243526_aaa.html
I want to extract text, var and aaa and any variable texts from the code, but the numbers are variable.
Thanks,
Ted
|
|
|
|
03-10-2012, 09:27 PM
|
#2
|
|
Senior Member
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,167
|
Hi Ted,
If I understand correctly, you're trying to get the the foo_bar.html components in the file name, foo and bar?
Code:
echo $your_file_list | sed -r 's@.*/(.*)_(.*).html@one=\1 two=\2@'
|
|
|
1 members found this post helpful.
|
03-10-2012, 10:55 PM
|
#3
|
|
Member
Registered: Aug 2010
Location: Zhongli, Taoyuan
Distribution: slackware, windows, debian (armv4l GNU/Linux)
Posts: 404
Original Poster
Rep:
|
thanks, yes, you understand it correctly. Is there a way to use \d to strictly match the number?
|
|
|
|
03-10-2012, 11:46 PM
|
#4
|
|
Guru
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 6,328
|
Assuming you get \d from Perl then you are looking for [0-9]
|
|
|
|
03-11-2012, 12:27 AM
|
#5
|
|
Member
Registered: Aug 2010
Location: Zhongli, Taoyuan
Distribution: slackware, windows, debian (armv4l GNU/Linux)
Posts: 404
Original Poster
Rep:
|
Code:
sh-3.1# echo "/topics/view/24555_3333_text.html" | sed -r 's@.*/?([0-9])_(.*).ht
ml@\2@'
text
I tried the above code, but the output I desired is:
3333_text
How do i fix this?
Thanks,
Ted
|
|
|
|
03-11-2012, 01:07 AM
|
#6
|
|
Guru
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 6,328
|
Maybe you could explain the regex as it does not make sense to me?
|
|
|
|
03-11-2012, 07:55 AM
|
#7
|
|
Member
Registered: Mar 2006
Location: Ekaterinburg, Russia
Distribution: Debian, Ubuntu
Posts: 577
|
Hi.
Code:
$ echo "/topics/view/24555_3333_text.html" | sed -r 's/[^_]*_(.*).html/\1/'
3333_text
|
|
|
1 members found this post helpful.
|
| 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 10:45 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
|
|