[nycbug-talk] sed Question
Jan Schaumann
jschauma at netmeister.org
Thu Mar 30 19:23:33 EST 2006
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. :-)
-Jan
--
The reader is encouraged to add smileys where necessary to increase
positive perception. Right here might be a good place:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 186 bytes
Desc: not available
URL: <https://lists.nycbug.org:8443/pipermail/talk/attachments/20060330/3ac7027f/attachment.bin>
More information about the talk
mailing list