LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   regex text (http://www.linuxquestions.org/questions/programming-9/regex-text-933832/)

ted_chou12 03-10-2012 09:23 PM

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

jhwilliams 03-10-2012 09:27 PM

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@'

ted_chou12 03-10-2012 10:55 PM

thanks, yes, you understand it correctly. Is there a way to use \d to strictly match the number?

grail 03-10-2012 11:46 PM

Assuming you get \d from Perl then you are looking for [0-9]

ted_chou12 03-11-2012 12:27 AM

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

grail 03-11-2012 01:07 AM

Maybe you could explain the regex as it does not make sense to me?

firstfire 03-11-2012 07:55 AM

Hi.

Code:

$ echo "/topics/view/24555_3333_text.html" | sed -r 's/[^_]*_(.*).html/\1/'
3333_text



All times are GMT -5. The time now is 02:49 PM.