sed ?
Dave
Dave
Sun Dec 11 02:22:57 AEST 1988
While we're at it, how exactly does _s_e_d work through the stdin? Here
is a little script we whipped up to find anyone else who played the
game _h_u_n_t at other sites. It was grossly out of hand, but hey --
most of us have done such extravagant things before.
#!/bin/csh -f
ypcat hosts > /tmp/hosts
cat /dev/null > /tmp/hunters
tail -f /tmp/hunters & /* thrown in when I decided on doing it all in bg */
@ line = 0
@ loop = `wc -l /tmp/hosts`
while(line < loop)
@ line = line + 1
**** see below for choices for this line ****
hunt -q $site |& grep -v pawl.rpi.edu >> /tmp/hunters
end
**** choices:
set site = `sed -n ${line}P /tmp/hosts | cut -f2 | cut -f2 -d" "`
or
set site = `tail +$line /tmp/hosts | head -1 | cut -f2 | cut -f2 -d" "`
Now silly me, I thought _s_e_d would be the faster one because all it would
do would be to jump in and take only the line it needed (perhaps reading
all the lines before it.) At any rate, thought I, _s_e_d would be faster
a the first half because it would read to the line from the beginning, while
_t_a_i_l was processing all the stuff at the end.
To test the more efficient one (a C-programme or such would probably be
most efficient, but we didn't want to spend any real time on this), we
threw in an 'echo $site' after the set statement and found that the
_t_a_i_l pipeline was working faster. Why should this be? Anyone know how
_s_e_d finds a line in a file? JOC, can any suggest a really efficient way
of doing this?
BTW -- the double _c_u_t in the pipeline is necessary because whoever
maintains the yp hosts database managed to corrupt it in a lot of
formatting regards. That was the only sure fire way to get almost
all of the addresses.
Dave
--
tale at rpitsmts.bitnet, tale%mts at rpitsgw.rpi.edu, tale at pawl.rpi.edu
More information about the Comp.unix.wizards
mailing list