LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-14-2012, 05:39 AM   #1
deepinlife
Member
 
Registered: Apr 2006
Posts: 78

Rep: Reputation: 15
sed slashs


using sed , i captured text from a file using 2 keywords strings

Code:
sed -n '/\<div\ id=\"ctl00_ContentPlaceHolder1_BookBref\"\ class=\"bref\"\ style=\"float\:left\;text-align\:left\;\">/,/<\/div>/P'
when i tested it on a file , it get the text but somehow it ignors the ending keyword
Code:
/<\/div>/
it ignors the first occurance of teh keyword but took the next one
Quote:
<div id="ctl00_ContentPlaceHolder1_BookBref" class="bref" style="float:left;text-align:left;">Get complete coverage of the latest release of the CompTIA A+ exams inside this fully revised and updated resource. Written by the leading authority on CompTIA A+ certification and training, this expert guide covers CompTIA A+ exams 220-701 and 220-702. You'll find learning objectives at the beginning of each chapter, exam tips, practice exam questions, in-depth explanations, and more than 1,000 photographs and illustrations. Designed to help you pass the CompTIA A+ exams with ease, this definitive volume also serves as an essential on-the-job IT reference. Covers all exam objectives, including how to: Work with CPUs, RAM, motherboards, power supplies, and other PC components Install, partition, and format hard drives Install, upgrade, and troubleshoot WIndows 2000, Windows XP, and Windows Vista Troubleshoot PCs and implement security measures Install video and multimedia cards Work with portable PCs, PDAs, smartphones, and wireless technologies Manage printers and connect to networks and the Internet Understand safety and environmental issues Establish good communication skills and adhere to privacy policies The CD-ROM features: Practice exams for 701 &amp; 702 600+ chapter review questions New video introduction to CompTIA A+ One-hour video training segment Mike's favorite PC tools and utilities Searchable e-book Mike Meyers, CompTIA A+, CompTIA Network+, MCP, is the industry's leading authority on CompTIA A+ certification and training. He is the president and founder of Total Seminars, LLC, a major provider of PC and network repair seminars for thousands of organizations throughout the world, and a member of CompTIA. </div>
<div class="lien_book">
</div>
why ?

sed version
GNU sed version 4.2.1
linux ubuntu 11.10

Last edited by deepinlife; 03-14-2012 at 05:44 AM. Reason: forgot to mention sed version
 
Old 03-14-2012, 09:27 AM   #2
sysmicuser
Member
 
Registered: Mar 2010
Posts: 359

Rep: Reputation: 0
You are using "/" as your delimiter, you can use pretty-much anything, try with "@" and let me know how does it goes.

Cheers
 
Old 03-22-2012, 03:55 AM   #3
deepinlife
Member
 
Registered: Apr 2006
Posts: 78

Original Poster
Rep: Reputation: 15
still the same
Code:
sed -n '\@<div id="ctl00_ContentPlaceHolder1_BookBref" class="bref" style="float:left;text-align:left;">@,\@</div>@P'
i even tried this but of no use!!
Code:
sed -n '\@<div id="ctl00_ContentPlaceHolder1_BookBref" class="bref" style="float:left;text-align:left;">@,\@div>@P'
 
Old 03-22-2012, 04:07 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,563

Rep: Reputation: 2900Reputation: 2900Reputation: 2900Reputation: 2900Reputation: 2900Reputation: 2900Reputation: 2900Reputation: 2900Reputation: 2900Reputation: 2900Reputation: 2900
COUld you perhaps explain further what you are trying to accomplish?
 
Old 03-22-2012, 04:13 AM   #5
jack_9
LQ Newbie
 
Registered: May 2011
Posts: 23

Rep: Reputation: Disabled
Hey deepinlife,

Can you make your query simple.. What you want to do wth this file... wht output do you want..

I understood that you want to do something with following chunk:

Quote:
<div id="ctl00_ContentPlaceHolder1_BookBref" class="bref" style="float:left;text-align:left;"></div>
<div class="lien_book">
</div>
And this is ur code:

Quote:
sed -n '/\<div\ id=\"ctl00_ContentPlaceHolder1_BookBref\"\ class=\"bref\"\ style=\"float\:left\;text-align\:left\;\">/,/<\/div>/P'
however I cant understand wht r u trying to escape here "<div\"
 
Old 03-22-2012, 11:21 AM   #6
Sydney
Member
 
Registered: Mar 2012
Distribution: Scientific Linux
Posts: 147

Rep: Reputation: 36
Sorry if I misunderstand your issue, but you should be able to add a g for global to catch it more than once. Otherwise it would only trigger on the first instance.
 
Old 03-25-2012, 07:16 AM   #7
deepinlife
Member
 
Registered: Apr 2006
Posts: 78

Original Poster
Rep: Reputation: 15
@Sydney thx i forgot to add g , i added now.
further explaination

a file containing some text , i want to copy that text to another file , the text is marked between 2 key words
Code:
<div id="ctl00_ContentPlaceHolder1_BookBref" class="bref" style="float:left;text-align:left;">
and
Code:
</div>
the problem is that the command i used , ignores the ending key and keep searching for it untill it find the second occurance of it after one line more
 
Old 03-25-2012, 08:12 AM   #8
Sydney
Member
 
Registered: Mar 2012
Distribution: Scientific Linux
Posts: 147

Rep: Reputation: 36
Did that resolve your issue?
 
Old 03-25-2012, 08:31 AM   #9
deepinlife
Member
 
Registered: Apr 2006
Posts: 78

Original Poster
Rep: Reputation: 15
unfortantly no
 
Old 03-25-2012, 09:02 AM   #10
Sydney
Member
 
Registered: Mar 2012
Distribution: Scientific Linux
Posts: 147

Rep: Reputation: 36
sed -n "s/.*\(<div\ id=\"ctl00_ContentPlaceHolder1_BookBref\"\ class=\"bref\"\ style=\"float\:left\;text-align\:left\;\">.*<\/div>\).*/\1/p"

Last edited by Sydney; 03-25-2012 at 09:04 AM.
 
Old 03-25-2012, 10:16 AM   #11
deepinlife
Member
 
Registered: Apr 2006
Posts: 78

Original Poster
Rep: Reputation: 15
@Sydney
it works !! thx
but can u explain \1 means ? doesit mena display ? does it ignores s command ?

and can u tell why it didnt work on using ranges as i was using ?
 
Old 03-25-2012, 10:42 AM   #12
Sydney
Member
 
Registered: Mar 2012
Distribution: Scientific Linux
Posts: 147

Rep: Reputation: 36
Actually those questions are both answered in this well done article by Bruce Barnett about using SED, this part specifically talks about \1 and why your expression was matching more than you wanted. http://www.grymoire.com/Unix/Sed.html#uh-4
 
  


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
sed and regexp matching (GNU sed version 4.2.1) Ashkhan Programming 8 02-27-2012 10:12 AM
[SOLVED] head -n -1 (sed -n -e '1,$-1p' is incorrect) sed question, as stupid as it could be. kaz2100 Programming 1 12-27-2011 10:18 PM
[SOLVED] sed 's/Tb05.5K5.100/Tb229/' alone but doesn't work in sed file w/ other expressions Radha.jg Programming 6 03-03-2011 08:59 AM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 07:12 AM
Using echo to output a string to a file with forward slashs chrisk5527 Linux - General 15 06-21-2003 03:04 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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