smileyf@ucscb.UCSC.EDU (Shutoku Shia) (12/09/88)
I would like to know how to do the following with sed: 1) how to use substitution and negation(!) in a sed script, for example, suppose I DO NOT want to apply the following substitution "s/foo/FOO/g" on line(s) for which "/^\/$/" apply. 2) does anyone know of a sample sed script which allow one to modify a file, however, in this case, both the input file and the output file is the same file (input file does not refer to the instuction file -- i.e. sed script is NOT input file). In ex terms, what is the sed equivalent of, ex - junk <<EOF ex script ex script ... w EOF Please send me email if you know solutions. Thanks. Shutoku +---------------------------------------+-----------------------------+ | Bitnet: smileyf@ucscf.bitnet | | | Internet: smileyf@ucscf.UCSC.EDU | | | Arpanet: smileyf@ucscf.UCSC.EDU | Univ. of Calif., Santa Cruz | | Uucp: ...!ucbvax!ucscc!ucscf!smileyf | | +---------------------------------------+-----------------------------+
Dave Lawrence (12/11/88)
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@rpitsmts.bitnet, tale%mts@rpitsgw.rpi.edu, tale@pawl.rpi.edu