sed command line help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • acctman
    Confirmed User
    • Oct 2003
    • 2840

    #1

    sed command line help

    I'm trying to get this sed command to work correctly. I need to retrieve a specific "string" from: terms_id=string&location
    below is what i'm working with so far.

    Code:
    sed -ne 's/^.*terms_id=\([^&]*\)&.*$/\1/'
  • fris
    Too lazy to set a custom title
    • Aug 2002
    • 55679

    #2
    whats wrong with it?

    test.txt

    terms_id=shit&location
    terms_id=sex&location
    terms_id=scat&location
    terms_id=porn&location
    terms_id=bbw&location
    terms_id=teen&location
    [chris@jumbo ~]$ sed 's/^.*terms_id=\([^&]*\)&.*$/\1/' test.txt
    shit
    sex
    scat
    porn
    bbw
    teen
    Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.

    Comment

    • acctman
      Confirmed User
      • Oct 2003
      • 2840

      #3
      Originally posted by fris
      whats wrong with it?

      test.txt
      hmm I noticed that you removed -ne, it works without that. also is there a way to make it append the outputs each time the command is run? it seems to be writing a new file each time I run the command. thanks

      Code:
      sed 's/^.*terms_id=\([^&]*\)&.*$/\1/' test.txt > getIDs.txt

      Comment

      • fris
        Too lazy to set a custom title
        • Aug 2002
        • 55679

        #4
        test.txt >> getIDS.txt
        Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.

        Comment

        • CYF
          Coupon Guru
          • Mar 2009
          • 10973

          #5
          Originally posted by acctman
          hmm I noticed that you removed -ne, it works without that. also is there a way to make it append the outputs each time the command is run? it seems to be writing a new file each time I run the command. thanks

          Code:
          sed 's/^.*terms_id=\([^&]*\)&.*$/\1/' test.txt > getIDs.txt
          sed 's/^.*terms_id=\([^&]*\)&.*$/\1/' test.txt >> getIDs.txt
          Webmaster Coupons Coupons and discounts for hosting, domains, SSL Certs, and more!
          AmeriNOC Coupons | Certified Hosting Coupons | Hosting Coupons | Domain Name Coupons

          Comment

          • acctman
            Confirmed User
            • Oct 2003
            • 2840

            #6
            thanks Fris and CYF

            Comment

            • acctman
              Confirmed User
              • Oct 2003
              • 2840

              #7
              back with another question. it keeps grabbing all the html coding around the string. I can see that its finding the string in the output but its also grabbing the html coding content as well.


              Code:
              #! /bin/sh
              
              if [ $# -ne 2 ]; then
                  echo "usage: $0 termfile baseurl" >&2
                  exit 1
              fi
              termfile="$1"
              baseurl="$2"
              
              while read term; do
                  wget -q -O- "$baseurl/server.php?all=$term" |
              		sed 's/^.*terms_id=\([^&]*\)&.*$/\1/'
              done < "$termfile"

              Comment

              Working...