You are not logged in.

#1 2010-04-05 22:59:33

Arm-the-Homeless
Member
Registered: 2008-12-22
Posts: 273

[SOLVED] Need Help with Sed

Since I'm a dirty TF2 idler and I use Source Tools to idle, it uses a list of servers from a servers.txt file.

A list of idling servers is here: http://tf2stats.net/blacklist_generate/ … ourcetools
The list is in this format:
{IP ADDRESS}:{PORT};{SERVER NAME}

Unfortunately, I can't just save that as the list, because it thinks you're trying to send {SERVER NAME} as a command or something.
There's ~920 lines that are just that and so I need to remove everything AFTER the port number (so it would be the colon and the server name).

The tricky part is that not all ports are the same. 27015 is the standard, some use 27016, and some use other ones. So I need to have a sed command to remove everything past a colon on all lines, then remove the colon on all lines.

And since I suck at sed, I've come crawling to the forums for help. So please, help. tongue

Last edited by Arm-the-Homeless (2010-04-05 23:47:19)

Offline

#2 2010-04-05 23:10:34

tavianator
Member
From: Waterloo, ON, Canada
Registered: 2007-08-21
Posts: 859
Website

Re: [SOLVED] Need Help with Sed

Um, sed 's/\(.*\):\([[:digit:]]*\);\(.*\)/\1/g' will give you just the IPs.  Replacing '\1' with '\2' will get you the port, and '\3' gets you the server name.  '\1:\2' will get you {SEVER}:{PORT}.

Offline

#3 2010-04-05 23:41:47

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,799
Website

Re: [SOLVED] Need Help with Sed

alternatively you could do it in pure bash too.

(
IFS=$'\n'; while read -r; do
  echo "${REPLY%%;*}" 
done < <(wget -q -O - "http://thaturl.com")
) > ./serverlist.txt

that would get your list of server:port in a text file.

Offline

#4 2010-04-05 23:46:55

Arm-the-Homeless
Member
Registered: 2008-12-22
Posts: 273

Re: [SOLVED] Need Help with Sed

Thanks. Just what I needed. big_smile

Offline

#5 2010-04-06 06:41:43

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: [SOLVED] Need Help with Sed

@tavianator: If the server name has a : and ; in the server name then that won't work. Instead use [^:]*: and [^;]*;

@brisbin33: if you're going to redefine IFS, why not to :; with while read ip port name

Offline

#6 2010-04-06 13:29:58

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,799
Website

Re: [SOLVED] Need Help with Sed

Procyon wrote:

@brisbin33: if you're going to redefine IFS, why not to :; with while read ip port name

true story.  IFS=$'\n'; while read -r is just a habit i fall back on when i want to read [possibly inconsistent] lines out of a file.

Offline

Board footer

Powered by FluxBB