[nycbug-talk] sed Question

Kevin Reiter tux at penguinnetwerx.net
Thu Mar 30 19:06:32 EST 2006


Jan Schaumann wrote:
> Kevin Reiter <tux at penguinnetwerx.net> wrote:
>  
>> #!/bin/sh
>>
>> 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`
> 
> You can do that without any temporary files (and one pipe less):
> 
> fastest=`fastest_cvsup -c us | awk '/1st/ {print $3;}'`
> sed -e "s/host=cvsup.*FreeBSD\.org/host=$fastest/" ports-sup
>       ^^^
> 
> Use regular quotes (") instead of ', otherwise the variable '$fastest'
> won't be expanded.

Tried that, but it didn't write to the file (ports-sup):

kevin at chronos [~/scripts/practice/sed]$ ./update_ports.sh

Finding the fastest cvsup server and modifying
/root/ports-sup to use that server.

*default tag=.
*default host=cvsup3.us.freebsd.org
*default prefix=/usr
*default base=/usr/local/cvsup
*default release=cvs delete use-rel-suffix compress

ports-all


Done.  Now run cvsup ports-sup from root's directory.

kevin at chronos [~/scripts/practice/sed]$ cat fast.txt
cvsup11.us.freebsd.org
kevin at chronos [~/scripts/practice/sed]$ cat ports-sup
*default tag=.
*default host=cvsup11.FreeBSD.org
*default prefix=/usr
*default base=/usr/local/cvsup
*default release=cvs delete use-rel-suffix compress

ports-all


kevin at chronos [~/scripts/practice/sed]$

(I'm not writing to /root/ports-sup, but a copy of it in that directory)



More information about the talk mailing list