home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Trees / V7 / usr / doc / edtut / e2 < prev    next >
Encoding:
Text File  |  1979-01-10  |  6.8 KB  |  428 lines

  1. .SH
  2. Writing text out as a file \- the Write command ``w''
  3. .PP
  4. It's likely that you'll want to save your text for later use.
  5. To write out the contents of the buffer onto a file,
  6. use the
  7. .ul
  8. write
  9. command
  10. .P1
  11. w
  12. .P2
  13. followed by the filename you want to write on.
  14. This will copy the buffer's contents
  15. onto the specified file
  16. (destroying any previous information on the file).
  17. To save
  18. the text on a file named
  19. .UL junk ,
  20. for example, type
  21. .P1
  22. w junk
  23. .P2
  24. Leave a space between
  25. .UL w
  26. and the file name.
  27. .ul
  28. Ed
  29. will respond by printing
  30. the number of characters it wrote out.
  31. In this case,
  32. .ul
  33. ed
  34. would respond with
  35. .P1
  36. 68
  37. .P2
  38. (Remember that blanks and the return character at the end of each
  39. line are included in the character count.)
  40. Writing a file just makes a copy of the text \- the
  41. buffer's contents are not disturbed, so you can go on adding
  42. lines to it.
  43. This is an important point.
  44. .ul
  45. Ed
  46. at all times works on a copy
  47. of a file, not the file itself.
  48. No change in the contents
  49. of a file takes place until you give a
  50. .UL w
  51. command.
  52. (Writing out the text onto a file from time to time as it is being
  53. created is a good idea, since if the system crashes or if you make some horrible mistake, you will lose
  54. all the text in the buffer but any text that was written onto
  55. a file is relatively safe.)
  56. .SH
  57. Leaving ed \- the Quit command ``q''
  58. .PP
  59. To terminate a session with
  60. .IT ed ,
  61. save the text you're working on
  62. by writing it onto a file using the
  63. .UL w
  64. command,
  65. and then type the command
  66. .P1
  67. q
  68. .P2
  69. which
  70. stands for
  71. .IT quit .
  72. The system will respond with
  73. the prompt character
  74. .UL $ "" (
  75. or
  76. .UL % ).
  77. At
  78. this point your buffer vanishes, with all its text,
  79. which is why you want to write it out before quitting.\(dg
  80. .FS
  81. \(dg Actually,
  82. .IT ed
  83. will print 
  84. .UL ?
  85. if you try to quit without writing.
  86. At that point, write if you want;
  87. if not, another
  88. .UL q
  89. will get you out regardless.
  90. .FE
  91. .SH
  92. Exercise 1:
  93. .PP
  94. Enter
  95. .ul
  96. ed
  97. and
  98. create some text using
  99. .P1
  100. a
  101. \&. . . text . . .
  102. \&\fB.\fR
  103. .P2
  104. Write it out using
  105. .UL w .
  106. Then leave
  107. .ul
  108. ed
  109. with the
  110. .UL q
  111. command, and print the file,
  112. to see that everything worked.
  113. (To print a file, say
  114. .P1
  115. pr filename
  116. .P2
  117. or
  118. .P1
  119. cat filename
  120. .P2
  121. in response to
  122. the prompt character.
  123. Try both.)
  124. .SH
  125. Reading text from a file \- the Edit command ``e''
  126. .PP
  127. A common way to get text into the buffer is to read it
  128. from a file in the file system.
  129. This is what you do to edit text
  130. that you saved with the 
  131. .UL w
  132. command in a previous session.
  133. The
  134. .ul
  135. edit
  136. command
  137. .UL e
  138. fetches the entire contents of a file into the buffer.
  139. So if you had saved the three lines
  140. ``Now is the time'', etc.,
  141. with a
  142. .UL w
  143. command in an earlier session,
  144. the 
  145. .ul
  146. ed
  147. command
  148. .P1
  149. e junk
  150. .P2
  151. would fetch the entire contents of the file
  152. .UL junk
  153. into the buffer, and respond
  154. .P1
  155. 68
  156. .P2
  157. which is the number of characters in
  158. .UL junk .
  159. .ul
  160. If anything was already in the buffer, it is deleted first.
  161. .PP
  162. If you use the
  163. .UL e
  164. command to read a file into the buffer,
  165. then you need not use a file name after a subsequent
  166. .UL w
  167. command;
  168. .ul
  169. ed
  170. remembers the last file name used in an
  171. .UL e
  172. command,
  173. and
  174. .UL w
  175. will write on this file.
  176. Thus a good way to operate is
  177. .P1
  178. ed
  179. e file
  180. [editing session]
  181. w
  182. q
  183. .P2
  184. This way, you can simply say
  185. .UL w
  186. from time to time,
  187. and be secure in the knowledge that
  188. if you got the file name right at the beginning,
  189. you are writing into the proper file each time.
  190. .PP
  191. You can find out at any time what file name
  192. .ul
  193. ed
  194. is remembering by typing the 
  195. .ul
  196. file
  197. command
  198. .UL f .
  199. In this example,
  200. if you typed
  201. .P1
  202. f
  203. .P2
  204. .ul
  205. ed
  206. would reply
  207. .P1
  208. junk
  209. .P2
  210. .SH
  211. Reading text from a file \- the Read command ``r''
  212. .PP
  213. Sometimes you want to read a file into the buffer
  214. without destroying anything that is already there.
  215. This is done by the
  216. .ul
  217. read
  218. command
  219. .UL r .
  220. The command
  221. .P1
  222. r junk
  223. .P2
  224. will read the file
  225. .UL junk
  226. into the buffer;
  227. it adds it
  228. to the end of whatever is already in the buffer.
  229. So if you do a read after
  230. an edit:
  231. .P1
  232. e junk
  233. r junk
  234. .P2
  235. the buffer will contain
  236. .ul
  237. two
  238. copies of the text (six lines).
  239. .P1
  240. Now is the time
  241. for all good men
  242. to come to the aid of their party.
  243. Now is the time
  244. for all good men
  245. to come to the aid of their party.
  246. .P2
  247. Like the
  248. .UL w
  249. and
  250. .UL e
  251. commands,
  252. .UL r
  253. prints
  254. the
  255. number of characters read in, after the reading operation is complete.
  256. .PP
  257. Generally speaking,
  258. .UL r
  259. is much less used than
  260. .UL e .
  261. .SH
  262. Exercise 2:
  263. .PP
  264. Experiment with the
  265. .UL e
  266. command \-
  267. try reading and printing various files.
  268. You may get an error
  269. .UL ?name ,
  270. where
  271. .UL name
  272. is the name of a file;
  273. this means that the file doesn't exist,
  274. typically because you spelled the file name wrong,
  275. or perhaps that you are not allowed to read or write it.
  276. Try alternately reading and appending to see that they work
  277. similarly.
  278. Verify that
  279. .P1
  280. ed filename
  281. .P2
  282. is exactly equivalent to
  283. .P1
  284. ed
  285. e filename
  286. .P2
  287. What does
  288. .P1
  289. f filename
  290. .P2
  291. do?
  292. .SH
  293. Printing the contents of the buffer \- the Print command ``p''
  294. .PP
  295. To
  296. .ul
  297. print
  298. or list the contents of the buffer (or parts
  299. of it) on the terminal, use the print command
  300. .P1
  301. p
  302. .P2
  303. The way this is done is as follows.
  304. Specify the lines where
  305. you want printing to begin and where you want it to end,
  306. separated by a comma, and
  307. followed by the letter
  308. .UL p .
  309. Thus to print the first two lines of the buffer, for
  310. example, (that is, lines 1 through 2) say
  311. .P1
  312. 1,2p    (starting line=1, ending line=2 p)
  313. .P2
  314. .ul
  315. Ed
  316. will respond with
  317. .P1
  318. Now is the time
  319. for all good men
  320. .P2
  321. .PP
  322. Suppose you want to print
  323. .ul
  324. all
  325. the lines in the buffer.
  326. You could use
  327. .UL 1,3p
  328. as above if you knew there were exactly
  329. 3 lines in the buffer.
  330. But in general, you don't
  331. know how many there are, so what do you use for the ending
  332. line number?
  333. .ul
  334. Ed
  335. provides a shorthand symbol for ``line number of
  336. last line in buffer'' \- the dollar sign
  337. .UL $ .
  338. Use it this
  339. way:
  340. .P1
  341. 1,$p
  342. .P2
  343. This will print
  344. .ul
  345. all
  346. the lines in the buffer (line 1 to last line.)
  347. If you want to stop the printing before it is finished,
  348. push the
  349. .UC DEL
  350. or Delete key;
  351. .ul
  352. ed
  353. will type
  354. .P1
  355. ?
  356. .P2
  357. and wait for the next command.
  358. .PP
  359. To print the
  360. .ul
  361. last
  362. line of the buffer, you could use
  363. .P1
  364. $,$p
  365. .P2
  366. but
  367. .ul
  368. ed
  369. lets you abbreviate this to
  370. .P1
  371. $p
  372. .P2
  373. You can print any single line by typing the line
  374. number followed by a
  375. .UL p .
  376. Thus
  377. .P1
  378. 1p
  379. .P2
  380. produces the response
  381. .P1
  382. Now is the time
  383. .P2
  384. which is the first line of the buffer.
  385. .PP
  386. In fact,
  387. .ul
  388. ed
  389. lets you abbreviate even further:
  390. you can print any single line by typing
  391. .ul
  392. just
  393. the line number \- no need to type the letter
  394. .UL p .
  395. So if you say
  396. .P1
  397. $
  398. .P2
  399. .ul
  400. ed
  401. will print the last line of the buffer.
  402. .PP
  403. You can also use
  404. .UL $
  405. in combinations like
  406. .P1
  407. $\-1,$p
  408. .P2
  409. which prints the last two lines of the buffer.
  410. This helps when you want to see how far you got in typing.
  411. .SH
  412. Exercise 3:
  413. .PP
  414. As before, create some text using the
  415. .UL a
  416. command and
  417. experiment with the
  418. .UL p
  419. command.
  420. You will find, for example,
  421. that you can't print line 0 or a line beyond
  422. the end of the buffer, and that attempts
  423. to print a buffer in reverse order by saying
  424. .P1
  425. 3,1p
  426. .P2
  427. don't work.
  428.