barad@othello.usc.edu (Herb Barad) (08/14/87)
In MPW Shell, I am trying to select the first line in a file (including the cr) and remove that line and all copies of that line. The way I tried in MPW shell is the following: Find /(?=dn)@1/ Replace -c inf /{@1}/ '' The "d" is really the delta, and the "=" is the curvy equal sign, and the "inf" is the infinity sign. I would think that the 1st line would find (and select) the first line from the cursor point (that contains at least 1 char) and the cr. It should assign this to the shell variable @1. Then, I will replace all occurances of the value of @1 with nothing. This doesn't work. I do know that: Find /?=dn/ will find and select the line (and cr) properly, but if I try Find /(?=dn)@1/ ; echo "{@1}" then the @1 is not assigned properly. Any ideas as to what I'm doing wrong. Thanks in advance. Herb Barad [USC - Signal and Image Processing Institute] email: barad@brand.usc.edu or ...!sdcrdcf!oberon!brand!barad
dwb@apple.UUCP (David W. Berry) (08/16/87)
In article <4021@oberon.USC.EDU> barad@othello.usc.edu () writes: >In MPW Shell, I am trying to select the first line in a file >(including the cr) and remove that line and all copies of that line. >The way I tried in MPW shell is the following: > >Find /(?=dn)@1/ >Replace -c inf /{@1}/ '' > >The "d" is really the delta, and the "=" is the curvy equal sign, and >the "inf" is the infinity sign. > >I would think that the 1st line would find (and select) the first line >from the cursor point (that contains at least 1 char) and the cr. It >should assign this to the shell variable @1. Then, I will replace all Here's the heart of the misunderstanding. The first line won't get stuck into a shell variable at all, but will rather be stored away somewhere in the actual command executing and not be carried forward to the replace. >occurances of the value of @1 with nothing. This doesn't work. I do >know that: I would try something like: Cut 1 # Cut out line one Open -t -n Tmp.File # Kludge to paste into command Paste *:inf # replace contents with line Target OriginalFile # go back to real file Find * # start at line one Replace -c inf del/*`cat Tmp.File`inf/:!1 '' # get rid of lines Delete Tmp.File Where funny characters are: * Bullet = option-8 inf Infinity = option-5 del Delta = option-j Note that the Replace command finds an affected line and extends the selection to exist from the start of the current selection to one character beyond it. That makes up for the fact that the cat on the command line will get the newline stripped out. -- David W. Berry dwb@well.uucp dwb@Delphi dwb@apple.com 293-0752@408.MaBell
lsr@apple.UUCP (Larry Rosenstein) (08/20/87)
In article <1482@apple.UUCP> dwb@apple.UUCP (David W. Berry) writes: >In article <4021@oberon.USC.EDU> barad@othello.usc.edu () writes: >>In MPW Shell, I am trying to select the first line in a file >>(including the cr) and remove that line and all copies of that line. >>The way I tried in MPW shell is the following: >> >>Find /(?=dn)@1/ >>Replace -c inf /{@1}/ '' >> >>... >> >>I would think that the 1st line would find (and select) the first line >>from the cursor point (that contains at least 1 char) and the cr. It >>should assign this to the shell variable @1. > >Here's the heart of the misunderstanding. The first line won't get >stuck into a shell variable at all, but will rather be stored away >somewhere in the actual command executing and not be carried forward > >I would try something like: >... Actually there is a much easier way. The following removes all the lines (including the first) from the target window that match the first line. find <option-8> # go to the top of the file find !0 # select the entire first line set str `catenate <option-6>` # put the first line into shell variable find <option-8> # go to the top of the file again replace -c <option-5> /{q}<option-d>n/ '' # do the replace Note that the <option-d>n in the replace search expression is needed; apparently the catenate strips it off. (The second find command does do the right thing, because if you cut the selected text the entire line is deleted.) The original idea of putting a tagged expression into a shell variable can be done, but you need to use the Evaluate command. For example, if the shell variable {file} contains a full pathname, the following extracts the volume and file name into 2 shell variables: evaluate "{file}" =~ /(<option-x>:)<option-r>1(<option-x>)<option-r>2/ This command does a pattern match between the filename and the regular expression on the right. It also has a side effect in that the shell variables {<option-r>1} and {<option-r>2} are set. (This also writes the result of the match something to stdout, so you usually want to surround the expression in parentheses and redirect stdout to dev:null.) I think you will find that the latter technique documented with the evaluate command. (It can be easy to overlook.) -- Larry Rosenstein Object Specialist Apple Computer AppleLink: Rosenstein1 UUCP: {sun, voder, nsc, mtxinu, dual}!apple!lsr CSNET: lsr@Apple.com