#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    16
    Rep Power
    0

    Using sed on grep results...


    I am trying to get some information from a load of different files (using grep) and then cut some of the information from it with sed. Unfortunately I know smeg all about sed and was wondering if you could help....

    Basically the script looks like ...


    #!/usr/local/bin/bash

    line2="http://www.myurl.com"
    dom_folder="domain/"
    line3="http://some.other.com"
    DB="test"


    grepline="domain/some.other.com/index.php?category=new:<img src=http://some.other.com/p.gif width=1 height=17><a href=http://www.myurl.com/ class=linkCat target=_blank>Blah blah blah blah...</a><br>"

    grep -iRs "<a href=${line2}" $dom_folder${line3#*/\/}/* | sed -e 's/^\(.*\)$/ UPDATE results set page='\1/' where url='${line3}'' | psql $DB

    The grepline is the results of the grep (obviously!) and what I need is the "index.php?category=new" bit...so I guess its a case of stripping up to the some.other.com and deleting everything after the ":". I need to put that page into a db, usually I use echo but amn't too sure if that'll work here.

    At the moment when I run it all I get is...

    [bash]#./blah.bash
    sed: here url=http://some.other.com: No such file or directory
    [bash]#


    Any help gratefully appreciated!!
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    16
    Rep Power
    0
    This did the trick....if anyone is interested!

    dom_no_slash="domain"
    page=`grep -iRs "<a href=${line2}" $dom_folder${line3#*/\/}/* | sed -e 's/'"$dom_no_slash"'\/'"${line3#*/\/}\/"'//g;s/:.*//g'`
    echo "UPDATE results set page='${page}' where url='${line3}'" | psql $DATABASE

IMN logo majestic logo threadwatch logo seochat tools logo