GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   sed command line help (https://gfy.com/showthread.php?t=980810)

acctman 08-02-2010 09:47 PM

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 08-02-2010 10:06 PM

whats wrong with it?

test.txt

Quote:

terms_id=shit&location
terms_id=sex&location
terms_id=scat&location
terms_id=porn&location
terms_id=bbw&location
terms_id=teen&location
Quote:

[chris@jumbo ~]$ sed 's/^.*terms_id=\([^&]*\)&.*$/\1/' test.txt
shit
sex
scat
porn
bbw
teen

acctman 08-02-2010 10:24 PM

Quote:

Originally Posted by fris (Post 17383220)
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

fris 08-02-2010 10:30 PM

test.txt >> getIDS.txt

CYF 08-02-2010 10:30 PM

Quote:

Originally Posted by acctman (Post 17383235)
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

acctman 08-02-2010 10:39 PM

thanks Fris and CYF :thumbsup

acctman 08-02-2010 11:54 PM

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"



All times are GMT -7. The time now is 09:47 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2026, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123