Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxn!ihnp4!houxm!hropus!ka From: ka@hropus.UUCP (Kenneth Almquist) Newsgroups: net.unix Subject: Re: global ed join Message-ID: <458@hropus.UUCP> Date: Wed, 14-May-86 19:38:02 EDT Article-I.D.: hropus.458 Posted: Wed May 14 19:38:02 1986 Date-Received: Sat, 17-May-86 01:38:06 EDT References: <359@ptsfd.UUCP> Organization: Bell Labs, Holmdel, NJ Lines: 43 Keywords: ed join global > Using ed on the "file" below (beginning with "stu_f_name Sam"), > g/stu_f//stu_f/,/stu_f/+1j joins the first and last names of the first two > "records" but not the last. Why doesn't it do the entire job? [The file > appears at the end of this article.] Here is what is happening. The "g" command sets dot to the first record of the file and executes the command "/stu_f/,/stu_f/+1j". Since searches start at the line *following* the current one, this joins the first two lines of the second record. The "g" command then skips over the second record because the first line of the second record was modified by the "j" command. ("g" makes this check to avoid infinite loops.) Then "g" executes the "j" command with dot set to the last record, which joins the first two lines of the first record. A good way to figure out what is happening with the "g" command is to add "p" and ".=" commands (or "n" if your editor supports it). Try g/stu_f/.=p\ /stu_f/,/stu_f+1/j\ .=p The way to join the first and second lines of each record is to say "g/stu_f/j". Kenneth Almquist ihnp4!houxm!hropus!ka (official name) ihnp4!opus!ka (shorter path) ------------------------ stu_f_name Sam Hazeltine phone 939393 ssn 030303030 stu_f_name Joe Waters phone 93939 ssn 030303030 stu_f_name Joe Waters phone 93939 ssn 030303030