LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-12-2014, 01:06 AM   #1
RandomTroll
Senior Member
 
Registered: Mar 2010
Distribution: Slackware
Posts: 2,024

Rep: Reputation: 273Reputation: 273Reputation: 273
A command works differently inside `` than outside


I want to pluck the title out of articles in 'Annals of Internal Medicine'. The titles appear in lines such as:

Quote:
<span id="ctl00_scm6MainContent_lblArticleTitle">What Can Medical Education Learn From Facebook and Netflix?<span class="alternateTitle">What Can
+Medical Education Learn From Facebook and Netflix?</span></span>
They recently introduced the alternate title, often a repeat of the
'main' title, sometimes a shortened version. Before that I could grep
on ctl00_scm6MainContent_lblArticleTitle and strip the html tags.

To address this complication I changed the algorithm to:

Quote:
Title=`grep ctl00_scm6MainContent_lblArticleTitle $file | sed 's/<span class="alternateTitle">/\
/g' | head -1 | html-strip`
which didn't work: it still returned both titles.

My problem is that

Quote:
grep ctl00_scm6MainContent_lblArticleTitle $file | sed 's/<span class="alternateTitle">/\
/g | head -1 | html-strip'
works outside of `` . The 'sed' statement isn't working the same inside of them.

I've missed something basic. I've used this maneuver before.
 
Old 05-12-2014, 01:36 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,684

Rep: Reputation: 7529Reputation: 7529Reputation: 7529Reputation: 7529Reputation: 7529Reputation: 7529Reputation: 7529Reputation: 7529Reputation: 7529Reputation: 7529Reputation: 7529
you will see it returns the "main" title and the alternate title together. I think it will do the same thing with and without backticks. Try this:
Code:
awk ' BEGIN { FS="[<>\"/]" } /ctl00_scm6MainContent_lblArticleTitle/ { print $9 } ' $file
 
Old 05-13-2014, 01:23 AM   #3
RandomTroll
Senior Member
 
Registered: Mar 2010
Distribution: Slackware
Posts: 2,024

Original Poster
Rep: Reputation: 273Reputation: 273Reputation: 273
It doesn't work the same inside the back-ticks as it does outside, at least not on my computer. That's the question I wanted answered. I've already found another tactic to solve this particular problem.

Your suggestion doesn't work: the relevant field varies between files.
 
Old 05-13-2014, 04:32 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,684

Rep: Reputation: 7529Reputation: 7529Reputation: 7529Reputation: 7529Reputation: 7529Reputation: 7529Reputation: 7529Reputation: 7529Reputation: 7529Reputation: 7529Reputation: 7529
one more comment to it:
\ may not be evaluated properly, but you can try to use $( command ) instead of ` command `. That may solve that issue
 
Old 05-13-2014, 06:48 AM   #5
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,137
Blog Entries: 1

Rep: Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874
nvm, not used to seeing sed used with multiple functions.

Last edited by Shadow_7; 05-13-2014 at 06:55 AM.
 
Old 05-13-2014, 06:56 AM   #6
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,137
Blog Entries: 1

Rep: Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874Reputation: 874
The `` is deprecated, you might see if $() gives the expected result.
 
  


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] Python 2.6 code behaves differently inside function than outside it dracuss Programming 2 03-21-2011 12:51 PM
[SOLVED] Command line works, won't work from inside bash script w6lsn Programming 4 02-17-2011 05:45 AM
Bash: command works but not inside of for loop. RijilV Programming 3 05-21-2006 08:29 PM
Debian: AWStats works differently when going to IP or hostname Punkrulz Linux - Software 0 01-13-2006 12:07 PM
SuSE works differently from Mandrake? escordeiro Linux - Newbie 1 09-30-2004 08:28 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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