[net.unix] global ed join

ria@ptsfd.UUCP (Rich Anderson) (05/12/86)

     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?

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

ka@hropus.UUCP (Kenneth Almquist) (05/15/86)

>      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

lapoint@BRL.ARPA (Claude Lapointe) (05/19/86)

I'm not sure exactly why it doesn't work, but i have verified that it doesn't.

I am concerned with the complexity of your command -- perhaps ed is becoming
confused with all the addresses: the form  "g/a//a/,/a/+1j" is indeed highly
redundant.

The form "g/a/.,.+1j" is "more correct" if such an expression may be used.

I have verified that "g/stu_f/.,.+1j" works.