[nycbug-talk] sed Question

Kevin Reiter tux at penguinnetwerx.net
Thu Mar 30 17:52:56 EST 2006


I know there are a few scripting gurus on this list who might be able to 
help me out with this..

I'm trying to write a script that does the following:

1. Runs 'fastest_cvsup -c us' to find the fastest cvsup server
2. Assigns the value of "server.txt" (which is the fastest server) to a 
variable and then searches my "ports-sup" file for the existing server, 
and replaces it with the new one.

Sofar, everything works fine until I get to the replacement part of the 

Here's the script:


echo ""
echo "Finding the fastest cvsup server."
echo ""
fastest_cvsup -c us | grep 1st | cut -d : -f 2 > server.txt
sed 's/^[ \t]*//' server.txt > fast.txt
fastest=`cat fast.txt`
echo ""
echo "The fastest server seems to be: $fastest"
echo ""
echo ""
echo "Here we actually modify the file using sed."
echo ""
sed '2s/cvsup*.FreeBSD.org/$fastest/' ports-sup
echo ""
echo Done.
rm server.txt
rm fast.txt

I've tried replacing '$fastest' with 'BLAH' and I'm still doing 
something wrong, but I don't know what.  I've been hitting Google pretty 
hard for a few days looking for some examples/pointers (which has gotten 
me this far) to no avail.

I'm looking to replace:

*default host=cvsup11.FreeBSD.org


*default host=cvsup##.FreeBSD.org (where ## is the actual number, like 2 
or 14 or whatever.)

Any ideas, or pointers to let me know what I'm doing wrong?


More information about the talk mailing list