Gawk Narrowing Down Search Results


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Gawk Narrowing Down Search Results
# 1  
Old 12-21-2012
Gawk Narrowing Down Search Results

I am using GAWK to search for a specific pattern:

Code:
gawk '{IGNORECASE=1;} /<a href=/&&/\$/,/<\/a/' index.html
<a class=author href="http://washingtondc.craigslist.org/search/?areaID=10&amp;amp;catAbb=sss&amp;amp;query=ps vita" title="craigslist washington, DC | all fo
r sale / wanted search &quot;ps vita&quot;">Craigslist Half Hourly Vista</a> <a href="http://washingtondc.craigslist.org/doc/vgd/3492907895.html" lang="en-us"
>Xbox 360 Elite   5 games (PWC) $135</a><div class="content">Hey craigslist, im selling my Xbox Elite as a Fighter Bundle. Most of the games are all fighting 
games. It comes with: Soul Calibur Soul Calibur Mortal Kombat () Dead or Alive Marvel vs Capcom A gig hard drive Wireless Controller All the Cables Im se [...
]</div></li>

The problem is that its spitting out an additional '<a </a>:
Code:
<a class=author href="http://washingtondc.craigslist.org/search/?areaID=10&amp;amp;catAbb=sss&amp;amp;query=ps vita" title="craigslist washington, DC | all fo
r sale / wanted search &quot;ps vita&quot;">Craigslist Half Hourly Vista</a>

and not just:

Code:
<a href="http://washingtondc.craigslist.org/doc/vgd/3492907895.html" lang="en-us"
>Xbox 360 Elite   5 games (PWC) $135</a><div class="content">Hey craigslist, im selling my Xbox Elite as a Fighter Bundle. Most of the games are all fighting 
games. It comes with: Soul Calibur Soul Calibur Mortal Kombat () Dead or Alive Marvel vs Capcom A gig hard drive Wireless Controller All the Cables Im se [...

Why is it not using my specific search criteria. What thought I was telling GAWK was to look for every occurrence that contains <a href= and $ and print everything in between and ends with <\/a. So in other words I only want to print out the line that contains only those specific criteria. ???
# 2  
Old 12-21-2012
Imagining the input or output in examples does not click for me. I think you are needing to split the lines with multiple <a>...</a> first. A little preprocessing makes many problems trivial. gawk ... | gawk ...
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. What is on Your Mind?

Search Results (Search, New, and Today's Topics) Animation Switch

Hey, I added an animation switch on the search results page; so by default the thread previews are off, but if you want to look at them, just click on the green button and the thread previews will turn on (and back off). See image and attached animation: ... (1 Reply)
Discussion started by: Neo
1 Replies

2. Shell Programming and Scripting

Narrowing sed Results in While Loop

find $SRC -type f -name *.emlx | while read FILE do if : then sed -n '/From/p' $FILE fi done > $DEST-output.txt The loop above spits out a .txt file with several lines that look like this: From: John Smith <jsmith@company.com> How can I narrow that sed result to spit out the email... (5 Replies)
Discussion started by: sudo
5 Replies

3. Shell Programming and Scripting

gawk script to search and replace text in a flat file

Hi I am new to unix and newbie to this forum. I need help in writing a gawk script that search and replace particular text in a flat file. Input file text : ZIDE_CONTROL000 100000000003869920900000300000001ISYNC 000002225489 0000000002232122 20120321 16:40:53 ZIDE_RECORD000... (5 Replies)
Discussion started by: gkausmel
5 Replies

4. Shell Programming and Scripting

Can ctag and cscope support recording search results and displaying the history results ?

Hello , When using vim, can ctag and cscope support recording search results and displaying the history results ? Once I jump to one tag, I can use :tnext to jump to next tag, but how can I display the preview search result? (0 Replies)
Discussion started by: 915086731
0 Replies

5. Shell Programming and Scripting

solved -gawk, search for pattern - mark the previous line as a variable?

Im trying to parse ifconfig with awk and setup a bunch of variables in one shot. But Im having trouble figuring out how to work with data in previous lines. ifconfig output: eth0 Link encap:Ethernet HWaddr 00:50:DA:10:7F:1B inet addr:10.10.10.10 Bcast:10.10.10.127 ... (0 Replies)
Discussion started by: trey85stang
0 Replies

6. Shell Programming and Scripting

Negate gawk search

Hi, I am using the under-noted script to search the "MYPATTERN" in MYFILE and print that block of lines containing the pattern starting with HEADER upto FOOTER. Please help me what to put in script to negate the search i.e. not to print those blocks meeting the search criteria. gawk -v... (1 Reply)
Discussion started by: vanand420
1 Replies

7. Shell Programming and Scripting

AWK - no search results

Hi all, I'm new to awk and I'm experiencing syntax error that I don't know how to resolve. Hopefully some experts in this forum can help me out. I created an awk file that look like this: $ cat myawk.awk BEGIN { VAR1=PATTERN1 VAR2=PATTERN2 } /VAR1/ { flag=1 } /VAR2/ { flag=0 } {... (7 Replies)
Discussion started by: hk18
7 Replies

8. Shell Programming and Scripting

Operations on search results

Hi, I am a newbie at Unix scritping, and I have a question. Looking at the search functionality on Unix. Here I have a structure root---------dir1 ------- file1, file2, file3 |_____dir2 ______file1@, file4 |_____dir3_______file1@, file5 Under root directory, I... (4 Replies)
Discussion started by: nj302
4 Replies
Login or Register to Ask a Question