sed matching


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sed matching
# 1  
Old 08-07-2016
sed matching

I need to extract text between numerous story-title=" "
Code:
<trending-story id="US_lnk_swT_mwAwAABMLM_en" sparkline="story.sparkline" story-index="(pageIndex * ctrl.trendingStoriesPerPage) + storyIndex + 1" story-title="Vaccine, Zika virus" story-title-array="story.entityNames" image-url="//t0.gstatic.

This outputs blank file:
Code:
sed -n '/^story-title="/s/\(.*"\)/\1/p' original > output

Thanks for guidance.
# 2  
Old 08-08-2016
With a standards-conforming version of sed, try:
Code:
sed -n 's/.* story-title="\([^"]*\)".*/\1/p' original > output

If you're using a GNU sed, you might need to use:
Code:
sed --posix -n 's/.* story-title="\([^"]*\)".*/\1/p' original > output

# 3  
Old 08-08-2016
Thanks, both those commands hang/freeze in bash terminal, but they led to solving in 2-parts, which I'd like to consolidate into 1:
Code:
sed -n '/story-title="/s/\(.*"\)/\1/p' original > output

this extracts just the trending-story line, omitting all unnecessary HTML:
Code:
<trending-story id="US_lnk_swT_mwAwAABMLM_en" sparkline="story.sparkline" story-index="(pageIndex * ctrl.trendingStoriesPerPage) 
+ storyIndex + 1" story-title="Vaccine, Zika virus" story-title-array="story.entityNames" image-url="//t0.gstatic.com/images?q=tbn:ANd9GcRbjJz
A7QdFk9ILYGiBBRNHdH3Q_S8hwVBzsBuEeZLNG-O1LoE2inJDx0aSQl6YuU24cRzhk2Faqyg" news-url="http://www.universityherald.com/articles/
36465/20160807/zika-vaccine-university-of-maryland-works-on-zika-vaccine-and-tests-on-human.htm" image-source="University Herald" hide-image=
"ctrl.hideAllImages" show-news-snippet="false" sparkline-size="ctrl.sparklineSize" class="ng-isolate-scope"><div class="trending-story-wrapper">

and this:
Code:
sed -r 's/.*story-title="([^"]+).*/\1/' output > output2

outputs what I want:
Code:
Vaccine, Zika virus

I tried running the sed -r command above with "original" file > output, and it also freezes/hangs in terminal. Anyhow, suggestion for consolidating the 2 working scripts would be appreciated.

Last edited by p1ne; 08-08-2016 at 01:00 PM.. Reason: code lines too long
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Use sed to get first matching pattern

HI, I have a file: listenerport: - 1521 - 10520 - 10521 - 10522 - 10523 instances: listenerport: listenerport: - 1521 - 10540 - 10541 - 10542 - 10543 instances: ... (5 Replies)
Discussion started by: netbanker
5 Replies

2. Shell Programming and Scripting

Help with sed pattern matching

Hi My log file is Testtmp2 cat Testtmp2 12:12:38 12:14:29 12:17:34 12:19:08 12:20:10 12:21:35 12:22:20 12:22:26 12:22:34 12:22:38 12:28:14 12:31:35 12:32:50 12:33:04 (3 Replies)
Discussion started by: rahkumar
3 Replies

3. Shell Programming and Scripting

help! Pattern Matching in vi or sed

I have a bunch of conf files, that contain the fully qualified names of servers. I would like to be able to use some sort of pattern matching with sed or vi, or whatever, to pull out the fully qualified server names, and dump them in a file. It just needs to work across several unix os. So, I... (4 Replies)
Discussion started by: tabini
4 Replies

4. Shell Programming and Scripting

SED pattern matching help

Hello All, I have the following lines in a file <address location="test" ConnectionName="test" /> I want to replace the above lines by <address location="test123" /> I am usind SED and not able to remove the new line characters between the two lines. Can anyone please help... (4 Replies)
Discussion started by: ramk
4 Replies

5. Shell Programming and Scripting

sed pattern matching

Unfortunately this chap has been banned for some reason and I was looking forward to the resolution of his question: - https://www.unix.com/shell-programming-scripting/123118-append-position-28-33-a.html He was asking if you can use sed to match a pattern you want to replace within a... (6 Replies)
Discussion started by: steadyonabix
6 Replies

6. Shell Programming and Scripting

sed pattern matching

Hi all, if I have the following piece (repeating) of text within a file and I wish to delete it via sed a b c d e <tr> <td><img alt="" height="1" width="3" src="/testweb/view/browser/images/shim.gif"></td><td><img alt="" height="1" ... (4 Replies)
Discussion started by: srage
4 Replies

7. Shell Programming and Scripting

matching ' in sed

Hi, I need to match some text in sed that contains the ' character. I have tried a escaped character but it doesn't work (that is, something like sed 's/\'/whatever/g') Does anyone know how to specify the ' character in the left part of sed? Thanks in advance. (2 Replies)
Discussion started by: luisrr
2 Replies

8. Shell Programming and Scripting

Matching everything on a line using sed

I having a little trouble. I want to substitute whatever is on the first line no matter what is on it with the word BEGINNING. So on the first line, the only word on it is BEGINNING I tried the following: sed '1,1s/^ *.*$/BEGINNING/g' $FILE It works only if the 1st line starts with a... (2 Replies)
Discussion started by: quixoticking11
2 Replies

9. Shell Programming and Scripting

Matching '/' in SED

Hello, I have a list of filename is a file called list.dat. The filenames appear in the list.dat file as this: ./set.class ./one.class I want to delete these file names from the list file using sed. To test I was trying to match just the set.class. Eventually I want to delete all... (5 Replies)
Discussion started by: bestbuyernc
5 Replies

10. Shell Programming and Scripting

Pattern matching sed

MSG="THERE WERE XX RECORDS IN ERROR TABLE,AAAA, WHEN LOADING THE BBBB TABLE WITH EXTRACT FROM CCCC INTO TABLES FOR , DATABASE DDDD." echo "$MSG" > /tmp/mplanmsg.$$.out I wan to replace XX with the content in $recordXX cat /tmp/mplanmsg.$$.out|sed 's/XX/\$recordXX/g'| sed... (3 Replies)
Discussion started by: leemjesse
3 Replies
Login or Register to Ask a Question