LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 03-10-2012, 10:23 PM   #1
ted_chou12
Member
 
Registered: Aug 2010
Location: Zhongli, Taoyuan
Distribution: slackware, windows, debian (armv4l GNU/Linux)
Posts: 421
Blog Entries: 28

Rep: Reputation: 2
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
 
Old 03-10-2012, 10:27 PM   #2
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 208Reputation: 208Reputation: 208
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.
Old 03-10-2012, 11:55 PM   #3
ted_chou12
Member
 
Registered: Aug 2010
Location: Zhongli, Taoyuan
Distribution: slackware, windows, debian (armv4l GNU/Linux)
Posts: 421
Blog Entries: 28

Original Poster
Rep: Reputation: 2
thanks, yes, you understand it correctly. Is there a way to use \d to strictly match the number?
 
Old 03-11-2012, 12:46 AM   #4
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,698

Rep: Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988
Assuming you get \d from Perl then you are looking for [0-9]
 
Old 03-11-2012, 01:27 AM   #5
ted_chou12
Member
 
Registered: Aug 2010
Location: Zhongli, Taoyuan
Distribution: slackware, windows, debian (armv4l GNU/Linux)
Posts: 421
Blog Entries: 28

Original Poster
Rep: Reputation: 2
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
 
Old 03-11-2012, 03:07 AM   #6
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,698

Rep: Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988Reputation: 1988
Maybe you could explain the regex as it does not make sense to me?
 
Old 03-11-2012, 08:55 AM   #7
firstfire
Member
 
Registered: Mar 2006
Location: Ekaterinburg, Russia
Distribution: Debian, Ubuntu
Posts: 640

Rep: Reputation: 375Reputation: 375Reputation: 375Reputation: 375
Hi.

Code:
$ echo "/topics/view/24555_3333_text.html" | sed -r 's/[^_]*_(.*).html/\1/'
3333_text
 
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] differences between shell regex and php regex and perl regex and javascript and mysql golden_boy615 Linux - General 2 04-19-2011 02:10 AM
combine text files with a regex itzfritz Linux - General 10 06-18-2009 02:26 PM
bash : crop some text with regex dodoecchi Programming 2 01-30-2009 02:10 PM
text manipulation, REGEX plus the following line farkus888 Solaris / OpenSolaris 3 02-27-2007 07:26 PM
Can you parse text with regex? raypen Slackware 4 03-21-2006 01:26 PM


All times are GMT -5. The time now is 06:44 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration