[nycbug-talk] sed Question

Kevin Reiter tux at penguinnetwerx.net
Thu Mar 30 20:17:32 EST 2006


Jan Schaumann wrote:
> Kevin Reiter <tux at penguinnetwerx.net> wrote:
>> 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):
> 
> Oh, of course not.  If you want to change the file in place do
> 
> fastest=`fastest_cvsup -c us | awk '/1st/ {print $3;}'`
> sed -e "s/host=cvsup.*FreeBSD\.org/host=$fastest/" ports-sup \
> 	> ports-sup.tmp && mv ports-sup.tmp ports-sup
> 
> Or generate input for and pipe it right to: ed(1).  (Left as an exercise
> for the reader. :-)

Oh sure.  NOW you tell me this :)

I must've had a huge brainfart to forget about that.  That's what I get 
for trying to fix a Windows machine while doing Unix scripting..

Thanks



More information about the talk mailing list