Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!think!ames!lll-tis!lll-lcc!pyramid!voder!apple!lsr From: lsr@apple.UUCP (Larry Rosenstein) Newsgroups: comp.sys.mac Subject: Re: MPW Shell question Message-ID: <1527@apple.UUCP> Date: Wed, 19-Aug-87 20:07:12 EDT Article-I.D.: apple.1527 Posted: Wed Aug 19 20:07:12 1987 Date-Received: Sat, 22-Aug-87 07:21:52 EDT References: <4021@oberon.USC.EDU> <1482@apple.UUCP> Reply-To: lsr@apple.UUCP (Larry Rosenstein) Distribution: world Organization: Advanced Technology Group, Apple Computer Lines: 63 Keywords: MPW Shell, regular expressions 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 # go to the top of the file find !0 # select the entire first line set str `catenate ` # put the first line into shell variable find # go to the top of the file again replace -c /{q}n/ '' # do the replace Note that the 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}" =~ /(:)1()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 {1} and {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