LinuxQuestions.org
Review your favorite Linux distribution.
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-11-2012, 03:43 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
sed match span text with style


Hi, I am trying to match:
Code:
<span style="display: none;">2012/03/10 19:44</span>
<span style="display: none;">2012/05/11 19:44</span>
<span style="display: none;">2012/04/10 06:44</span>
The "display: none;" will be consistent with a space in between strictly, the only variable is the time span and it is the actual string i am trying to extract.


Code:
sed -rn ':span style="display: none;">.*<\/span:\1:p' "$html"
Thanks,
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 03-11-2012, 04:14 PM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
It seems you missed the s command. Furthermore, you can't use a colon as separator, since it appears in the regular expression. Maybe you need something like this:
Code:
sed -r 's@<span style="display: none;">(.+)</span>@\1@' file
Hope this helps.
 
Old 03-11-2012, 06:30 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, but this seems to give me the whole file instead of the specific line.
Ted
 
Old 03-11-2012, 06:33 PM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Yeah, sorry. Just add the -n option and the p modifier as in your example:
Code:
sed -rn 's@<span style="display: none;">(.+)</span>@\1@p' file
 
2 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] How can I use sed to match this? ted_chou12 Linux - Newbie 13 12-09-2011 03:10 AM
[SOLVED] match html with sed ted_chou12 Linux - Newbie 7 12-06-2011 03:22 PM
sed match ted_chou12 Programming 7 04-20-2011 03:49 AM
make kde3 theme match with kde4 style almatic Linux - Desktop 0 03-11-2009 12:51 PM
grep/sed/awk - find match, then match on next line gctaylor1 Programming 3 07-11-2007 08:55 AM

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

All times are GMT -5. The time now is 03:56 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