LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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, 09:23 PM   #1
ted_chou12
Member
 
Registered: Aug 2010
Location: Zhongli, Taoyuan
Distribution: slackware, windows, debian (armv4l GNU/Linux)
Posts: 431
Blog Entries: 32

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

Rep: Reputation: 211Reputation: 211Reputation: 211
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, 10:55 PM   #3
ted_chou12
Member
 
Registered: Aug 2010
Location: Zhongli, Taoyuan
Distribution: slackware, windows, debian (armv4l GNU/Linux)
Posts: 431

Original Poster
Blog Entries: 32

Rep: Reputation: 3
thanks, yes, you understand it correctly. Is there a way to use \d to strictly match the number?
 
Old 03-10-2012, 11:46 PM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

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

Original Poster
Blog Entries: 32

Rep: Reputation: 3
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, 01:07 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

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

Rep: Reputation: 428Reputation: 428Reputation: 428Reputation: 428Reputation: 428
Hi.

Code:
$ echo "/topics/view/24555_3333_text.html" | sed -r 's/[^_]*_(.*).html/\1/'
3333_text
 
1 members found this post helpful.
  


Reply



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 01:10 AM
combine text files with a regex itzfritz Linux - General 10 06-18-2009 01:26 PM
bash : crop some text with regex dodoecchi Programming 2 01-30-2009 01:10 PM
text manipulation, REGEX plus the following line farkus888 Solaris / OpenSolaris 3 02-27-2007 06:26 PM
Can you parse text with regex? raypen Slackware 4 03-21-2006 12:26 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:08 PM.

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