summaryrefslogtreecommitdiffstats
path: root/man1p/ed.1p
blob: b7817a25775bfcf4b9af61b2c78aaac8146c12a3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved 
.TH "ED" P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual"
.\" ed 
.SH NAME
ed \- edit text
.SH SYNOPSIS
.LP
\fBed\fP \fB[\fP\fB-p\fP \fIstring\fP\fB][\fP\fB-s\fP\fB][\fP\fIfile\fP\fB]\fP
.SH DESCRIPTION
.LP
The \fIed\fP utility is a line-oriented text editor that uses two
modes: \fIcommand mode\fP and \fIinput mode\fP. In command
mode the input characters shall be interpreted as commands, and in
input mode they shall be interpreted as text. See the EXTENDED
DESCRIPTION section.
.SH OPTIONS
.LP
The \fIed\fP utility shall conform to the Base Definitions volume
of IEEE\ Std\ 1003.1-2001, Section 12.2, Utility Syntax Guidelines.
.LP
The following options shall be supported:
.TP 7
\fB-p\ \fP \fIstring\fP
Use \fIstring\fP as the prompt string when in command mode. By default,
there shall be no prompt string.
.TP 7
\fB-s\fP
Suppress the writing of byte counts by \fBe\fP, \fBE\fP, \fBr\fP,
and \fBw\fP commands and of the \fB'!'\fP prompt after
a !\fIcommand\fP.
.sp
.SH OPERANDS
.LP
The following operand shall be supported:
.TP 7
\fIfile\fP
If the \fIfile\fP argument is given, \fIed\fP shall simulate an \fBe\fP
command on the file named by the pathname,
\fIfile\fP, before accepting commands from the standard input. If
the \fIfile\fP operand is \fB'-'\fP , the results are
unspecified.
.sp
.SH STDIN
.LP
The standard input shall be a text file consisting of commands, as
described in the EXTENDED DESCRIPTION section.
.SH INPUT FILES
.LP
The input files shall be text files.
.SH ENVIRONMENT VARIABLES
.LP
The following environment variables shall affect the execution of
\fIed\fP:
.TP 7
\fIHOME\fP
Determine the pathname of the user's home directory.
.TP 7
\fILANG\fP
Provide a default value for the internationalization variables that
are unset or null. (See the Base Definitions volume of
IEEE\ Std\ 1003.1-2001, Section 8.2, Internationalization Variables
for
the precedence of internationalization variables used to determine
the values of locale categories.)
.TP 7
\fILC_ALL\fP
If set to a non-empty string value, override the values of all the
other internationalization variables.
.TP 7
\fILC_COLLATE\fP
.sp
Determine the locale for the behavior of ranges, equivalence classes,
and multi-character collating elements within regular
expressions.
.TP 7
\fILC_CTYPE\fP
Determine the locale for the interpretation of sequences of bytes
of text data as characters (for example, single-byte as
opposed to multi-byte characters in arguments and input files) and
the behavior of character classes within regular
expressions.
.TP 7
\fILC_MESSAGES\fP
Determine the locale that should be used to affect the format and
contents of diagnostic messages written to standard error and
informative messages written to standard output.
.TP 7
\fINLSPATH\fP
Determine the location of message catalogs for the processing of \fILC_MESSAGES
\&.\fP 
.sp
.SH ASYNCHRONOUS EVENTS
.LP
The \fIed\fP utility shall take the standard action for all signals
(see the ASYNCHRONOUS EVENTS section in \fIUtility Description Defaults\fP
) with the following exceptions:
.TP 7
SIGINT
The \fIed\fP utility shall interrupt its current activity, write the
string \fB"?\\n"\fP to standard output, and return to
command mode (see the EXTENDED DESCRIPTION section).
.TP 7
SIGHUP
If the buffer is not empty and has changed since the last write, the
\fIed\fP utility shall attempt to write a copy of the
buffer in a file. First, the file named \fBed.hup\fP in the current
directory shall be used; if that fails, the file named
\fBed.hup\fP in the directory named by the \fIHOME\fP environment
variable shall be used. In any case, the \fIed\fP utility
shall exit without returning to command mode.
.TP 7
SIGQUIT
The \fIed\fP utility shall ignore this event.
.sp
.SH STDOUT
.LP
Various editing commands and the prompting feature (see \fB-p\fP)
write to standard output, as described in the EXTENDED
DESCRIPTION section.
.SH STDERR
.LP
The standard error shall be used only for diagnostic messages.
.SH OUTPUT FILES
.LP
The output files shall be text files whose formats are dependent on
the editing commands given.
.SH EXTENDED DESCRIPTION
.LP
The \fIed\fP utility shall operate on a copy of the file it is editing;
changes made to the copy shall have no effect on the
file until a \fBw\fP (write) command is given. The copy of the text
is called the \fIbuffer\fP.
.LP
Commands to \fIed\fP have a simple and regular structure: zero, one,
or two \fIaddresses\fP followed by a single-character
\fIcommand\fP, possibly followed by parameters to that command. These
addresses specify one or more lines in the buffer. Every
command that requires addresses has default addresses, so that the
addresses very often can be omitted. If the \fB-p\fP option is
specified, the prompt string shall be written to standard output before
each command is read.
.LP
In general, only one command can appear on a line. Certain commands
allow text to be input. This text is placed in the
appropriate place in the buffer. While \fIed\fP is accepting text,
it is said to be in \fIinput mode\fP. In this mode, no
commands shall be recognized; all input is merely collected. Input
mode is terminated by entering a line consisting of two
characters: a period ( \fB'.'\fP ) followed by a <newline>. This line
is not considered part of the input text.
.SS Regular Expressions in ed
.LP
The \fIed\fP utility shall support basic regular expressions, as described
in the Base Definitions volume of
IEEE\ Std\ 1003.1-2001, Section 9.3, Basic Regular Expressions. Since
regular expressions in \fIed\fP are always matched against single
lines (excluding the terminating <newline>s), never
against any larger section of text, there is no way for a regular
expression to match a <newline>.
.LP
A null RE shall be equivalent to the last RE encountered.
.LP
Regular expressions are used in addresses to specify lines, and in
some commands (for example, the \fBs\fP substitute command)
to specify portions of a line to be substituted.
.SS Addresses in ed
.LP
Addressing in \fIed\fP relates to the current line. Generally, the
current line is the last line affected by a command. The
current line number is the address of the current line. If the edit
buffer is not empty, the initial value for the current line
shall be the last line in the edit buffer; otherwise, zero.
.LP
Addresses shall be constructed as follows:
.IP " 1." 4
The period character ( \fB'.'\fP ) shall address the current line.
.LP
.IP " 2." 4
The dollar sign character ( \fB'$'\fP ) shall address the last line
of the edit buffer.
.LP
.IP " 3." 4
The positive decimal number \fIn\fP shall address the \fIn\fPth line
of the edit buffer.
.LP
.IP " 4." 4
The apostrophe-x character pair ( \fB"'x"\fP ) shall address the line
marked with the mark name character \fIx\fP, which
shall be a lowercase letter from the portable character set. It shall
be an error if the character has not been set to mark a line
or if the line that was marked is not currently present in the edit
buffer.
.LP
.IP " 5." 4
A BRE enclosed by slash characters ( \fB'/'\fP ) shall address the
first line found by searching forwards from the line
following the current line toward the end of the edit buffer and stopping
at the first line for which the line excluding the
terminating <newline> matches the BRE. The BRE consisting of a null
BRE delimited by a pair of slash characters shall address
the next line for which the line excluding the terminating <newline>
matches the last BRE encountered. In addition, the
second slash can be omitted at the end of a command line. Within the
BRE, a backslash-slash pair ( \fB"\\/"\fP ) shall represent
a literal slash instead of the BRE delimiter. If necessary, the search
shall wrap around to the beginning of the buffer and
continue up to and including the current line, so that the entire
buffer is searched.
.LP
.IP " 6." 4
A BRE enclosed by question-mark characters ( \fB'?'\fP ) shall address
the first line found by searching backwards from the
line preceding the current line toward the beginning of the edit buffer
and stopping at the first line for which the line excluding
the terminating <newline> matches the BRE. The BRE consisting of a
null BRE delimited by a pair of question-mark characters (
\fB"??"\fP ) shall address the previous line for which the line excluding
the terminating <newline> matches the last BRE
encountered. In addition, the second question-mark can be omitted
at the end of a command line. Within the BRE, a
backslash-question-mark pair ( \fB"\\?"\fP ) shall represent a literal
question mark instead of the BRE delimiter. If necessary,
the search shall wrap around to the end of the buffer and continue
up to and including the current line, so that the entire buffer
is searched.
.LP
.IP " 7." 4
A plus-sign ( \fB'+'\fP ) or hyphen character ( \fB'-'\fP ) followed
by a decimal number shall address the current line
plus or minus the number. A plus-sign or hyphen character not followed
by a decimal number shall address the current line plus or
minus 1.
.LP
.LP
Addresses can be followed by zero or more address offsets, optionally
<blank>-separated. Address offsets are constructed
as follows:
.IP " *" 3
A plus-sign or hyphen character followed by a decimal number shall
add or subtract, respectively, the indicated number of lines
to or from the address. A plus-sign or hyphen character not followed
by a decimal number shall add or subtract 1 to or from the
address.
.LP
.IP " *" 3
A decimal number shall add the indicated number of lines to the address.
.LP
.LP
It shall not be an error for an intermediate address value to be less
than zero or greater than the last line in the edit
buffer. It shall be an error for the final address value to be less
than zero or greater than the last line in the edit buffer. It
shall be an error if a search for a BRE fails to find a matching line.
.LP
Commands accept zero, one, or two addresses. If more than the required
number of addresses are provided to a command that
requires zero addresses, it shall be an error. Otherwise, if more
than the required number of addresses are provided to a command,
the addresses specified first shall be evaluated and then discarded
until the maximum number of valid addresses remain, for the
specified command.
.LP
Addresses shall be separated from each other by a comma ( \fB','\fP
) or semicolon character ( \fB';'\fP ). In the case of
a semicolon separator, the current line ( \fB'.'\fP ) shall be set
to the first address, and only then will the second address
be calculated. This feature can be used to determine the starting
line for forwards and backwards searches; see rules 5. and 6.
.LP
Addresses can be omitted on either side of the comma or semicolon
separator, in which case the resulting address pairs shall be
as follows:
.TS C
center; l l.
\fBSpecified\fP	\fBResulting\fP
,	1 , $
, addr	1 , addr
addr ,	addr , addr
;	. ; $
; addr	. ; addr
addr ;	addr ; addr
.TE
.LP
Any <blank>s included between addresses, address separators, or address
offsets shall be ignored.
.SS Commands in ed
.LP
In the following list of \fIed\fP commands, the default addresses
are shown in parentheses. The number of addresses shown in
the default shall be the number expected by the command. The parentheses
are not part of the address; they show that the given
addresses are the default.
.LP
It is generally invalid for more than one command to appear on a line.
However, any command (except \fBe\fP, \fBE\fP,
\fBf\fP, \fBq\fP, \fBQ\fP, \fBr\fP, \fBw\fP, and \fB!\fP) can be suffixed
by the letter \fBl\fP, \fBn\fP, or \fBp\fP; in
which case, except for the \fBl\fP, \fBn\fP, and \fBp\fP commands,
the command shall be executed and then the new current line
shall be written as described below under the \fBl\fP, \fBn\fP, and
\fBp\fP commands. When an \fBl\fP, \fBn\fP, or \fBp\fP
suffix is used with an \fBl\fP, \fBn\fP, or \fBp\fP command, the command
shall write to standard output as described below, but
it is unspecified whether the suffix writes the current line again
in the requested format or whether the suffix has no effect. For
example, the \fBpl\fP command (base \fBp\fP command with an \fBl\fP
suffix) shall either write just the current line or write it
twice-once as specified for \fBp\fP and once as specified for \fBl\fP.
Also, the \fBg\fP, \fBG\fP, \fBv\fP, and \fBV\fP
commands shall take a command as a parameter.
.LP
Each address component can be preceded by zero or more <blank>s. The
command letter can be preceded by zero or more
<blank>s. If a suffix letter ( \fBl\fP, \fBn\fP, or \fBp\fP) is given,
the application shall ensure that it immediately
follows the command.
.LP
The \fBe\fP, \fBE\fP, \fBf\fP, \fBr\fP, and \fBw\fP commands shall
take an optional \fIfile\fP parameter, separated from
the command letter by one or more <blank>s.
.LP
If changes have been made in the buffer since the last \fBw\fP command
that wrote the entire buffer, \fIed\fP shall warn the
user if an attempt is made to destroy the editor buffer via the \fBe\fP
or \fBq\fP commands. The \fIed\fP utility shall write
the string:
.sp
.RS
.nf

\fB"?\\n"
\fP
.fi
.RE
.LP
(followed by an explanatory message if \fIhelp mode\fP has been enabled
via the \fBH\fP command) to standard output and shall
continue in command mode with the current line number unchanged. If
the \fBe\fP or \fBq\fP command is repeated with no
intervening command, it shall take effect.
.LP
If a terminal disconnect is detected:
.IP " *" 3
If the buffer is not empty and has changed since the last write, the
\fIed\fP utility shall attempt to write a copy of the
buffer to a file named \fBed.hup\fP in the current directory. If this
write fails, \fIed\fP shall attempt to write a copy of the
buffer to a filename \fBed.hup\fP in the directory named by the \fIHOME\fP
environment variable. If both these attempts fail,
\fIed\fP shall exit without saving the buffer.
.LP
.IP " *" 3
The \fIed\fP utility shall not write the file to the currently remembered
pathname or return to command mode, and shall
terminate with a non-zero exit status.
.LP
.LP
If an end-of-file is detected on standard input:
.IP " *" 3
If the \fIed\fP utility is in input mode, \fIed\fP shall terminate
input mode and return to command mode. It is unspecified if
any partially entered lines (that is, input text without a terminating
<newline>) are discarded from the input text.
.LP
.IP " *" 3
If the \fIed\fP utility is in command mode, it shall act as if a \fBq\fP
command had been entered.
.LP
.LP
If the closing delimiter of an RE or of a replacement string (for
example, \fB'/'\fP ) in a \fBg\fP, \fBG\fP, \fBs\fP,
\fBv\fP, or \fBV\fP command would be the last character before a <newline>,
that delimiter can be omitted, in which case
the addressed line shall be written. For example, the following pairs
of commands are equivalent:
.sp
.RS
.nf

\fBs/s1/s2   s/s1/s2/p
g/s1      g/s1/p
?s1       ?s1?
\fP
.fi
.RE
.LP
If an invalid command is entered, \fIed\fP shall write the string:
.sp
.RS
.nf

\fB"?\\n"
\fP
.fi
.RE
.LP
(followed by an explanatory message if \fIhelp mode\fP has been enabled
via the \fBH\fP command) to standard output and shall
continue in command mode with the current line number unchanged.
.SS Append Command
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB(.)a
<\fP\fItext\fP\fB>
\&.
\fP
.fi
.RE
.sp
.LP
The \fBa\fP command shall read the given text and append it after
the addressed line; the current line number shall become the
address of the last inserted line or, if there were none, the addressed
line. Address 0 shall be valid for this command; it shall
cause the appended text to be placed at the beginning of the buffer.
.SS Change Command
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB(.,.)c
<\fP\fItext\fP\fB>
\&.
\fP
.fi
.RE
.sp
.LP
The \fBc\fP command shall delete the addressed lines, then accept
input text that replaces these lines; the current line shall
be set to the address of the last line input; or, if there were none,
at the line after the last line deleted; if the lines deleted
were originally at the end of the buffer, the current line number
shall be set to the address of the new last line; if no lines
remain in the buffer, the current line number shall be set to zero.
Address 0 shall be valid for this command; it shall be
interpreted as if address 1 were specified.
.SS Delete Command
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB(.,.)d
\fP
.fi
.RE
.sp
.LP
The \fBd\fP command shall delete the addressed lines from the buffer.
The address of the line after the last line deleted shall
become the current line number; if the lines deleted were originally
at the end of the buffer, the current line number shall be set
to the address of the new last line; if no lines remain in the buffer,
the current line number shall be set to zero.
.SS Edit Command
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fBe\fP \fB[\fP\fIfile\fP\fB]\fP
.fi
.RE
.sp
.LP
The \fBe\fP command shall delete the entire contents of the buffer
and then read in the file named by the pathname \fIfile\fP.
The current line number shall be set to the address of the last line
of the buffer. If no pathname is given, the currently
remembered pathname, if any, shall be used (see the \fBf\fP command).
The number of bytes read shall be written to standard
output, unless the \fB-s\fP option was specified, in the following
format:
.sp
.RS
.nf

\fB"%d\\n", <\fP\fInumber of bytes read\fP\fB>
\fP
.fi
.RE
.LP
The name \fIfile\fP shall be remembered for possible use as a default
pathname in subsequent \fBe\fP, \fBE\fP, \fBr\fP, and
\fBw\fP commands. If \fIfile\fP is replaced by \fB'!'\fP , the rest
of the line shall be taken to be a shell command line
whose output is to be read. Such a shell command line shall not be
remembered as the current \fIfile\fP. All marks shall be
discarded upon the completion of a successful \fBe\fP command. If
the buffer has changed since the last time the entire buffer was
written, the user shall be warned, as described previously.
.SS Edit Without Checking Command
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fBE\fP \fB[\fP\fIfile\fP\fB]\fP
.fi
.RE
.sp
.LP
The \fBE\fP command shall possess all properties and restrictions
of the \fBe\fP command except that the editor shall not
check to see whether any changes have been made to the buffer since
the last \fBw\fP command.
.SS Filename Command
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fBf\fP \fB[\fP\fIfile\fP\fB]\fP
.fi
.RE
.sp
.LP
If \fIfile\fP is given, the \fBf\fP command shall change the currently
remembered pathname to \fIfile\fP; whether the name is
changed or not, it shall then write the (possibly new) currently remembered
pathname to the standard output in the following
format:
.sp
.RS
.nf

\fB"%s\\n", <\fP\fIpathname\fP\fB>
\fP
.fi
.RE
.LP
The current line number shall be unchanged.
.SS Global Command
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB(1,$)g/\fP\fIRE\fP\fB/\fP\fIcommand list\fP
.fi
.RE
.sp
.LP
In the \fBg\fP command, the first step shall be to mark every line
for which the line excluding the terminating <newline>
matches the given RE. Then, going sequentially from the beginning
of the file to the end of the file, the given \fIcommand list\fP
shall be executed for each marked line, with the current line number
set to the address of that line. Any line modified by the
\fIcommand list\fP shall be unmarked. When the \fBg\fP command completes,
the current line number shall have the value assigned
by the last command in the \fIcommand list\fP. If there were no matching
lines, the current line number shall not be changed. A
single command or the first of a list of commands shall appear on
the same line as the global command. All lines of a multi-line
list except the last line shall be ended with a backslash preceding
the terminating <newline>; the \fBa\fP, \fBi\fP, and
\fBc\fP commands and associated input are permitted. The \fB'.'\fP
terminating input mode can be omitted if it would be the
last line of the \fIcommand list\fP. An empty \fIcommand list\fP shall
be equivalent to the \fBp\fP command. The use of the
\fBg\fP, \fBG\fP, \fBv\fP, \fBV\fP, and \fB!\fP commands in the \fIcommand
list\fP produces undefined results. Any character
other than <space> or <newline> can be used instead of a slash to
delimit the RE. Within the RE, the RE delimiter
itself can be used as a literal character if it is preceded by a backslash.
.SS Interactive Global Command
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB(1,$)G/\fP\fIRE\fP\fB/
\fP
.fi
.RE
.sp
.LP
In the \fBG\fP command, the first step shall be to mark every line
for which the line excluding the terminating <newline>
matches the given RE. Then, for every such line, that line shall be
written, the current line number shall be set to the address of
that line, and any one command (other than one of the \fBa\fP, \fBc\fP,
\fBi\fP, \fBg\fP, \fBG\fP, \fBv\fP, and \fBV\fP
commands) shall be read and executed. A <newline> shall act as a null
command (causing no action to be taken on the current
line); an \fB'&'\fP shall cause the re-execution of the most recent
non-null command executed within the current invocation
of \fBG\fP. Note that the commands input as part of the execution
of the \fBG\fP command can address and affect any lines in the
buffer. Any line modified by the command shall be unmarked. The final
value of the current line number shall be the value set by
the last command successfully executed. (Note that the last command
successfully executed shall be the \fBG\fP command itself if a
command fails or the null command is specified.) If there were no
matching lines, the current line number shall not be changed. The
\fBG\fP command can be terminated by a SIGINT signal. Any character
other than <space> or <newline> can be used
instead of a slash to delimit the RE and the replacement. Within the
RE, the RE delimiter itself can be used as a literal character
if it is preceded by a backslash.
.SS Help Command
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fBh
\fP
.fi
.RE
.sp
.LP
The \fBh\fP command shall write a short message to standard output
that explains the reason for the most recent \fB'?'\fP
notification. The current line number shall be unchanged.
.SS Help-Mode Command
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fBH
\fP
.fi
.RE
.sp
.LP
The \fBH\fP command shall cause \fIed\fP to enter a mode in which
help messages (see the \fBh\fP command) shall be written to
standard output for all subsequent \fB'?'\fP notifications. The \fBH\fP
command alternately shall turn this mode on and off; it
is initially off. If the help-mode is being turned on, the \fBH\fP
command also explains the previous \fB'?'\fP notification,
if there was one. The current line number shall be unchanged.
.SS Insert Command
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB(.)i
<\fP\fItext\fP\fB>
\&.
\fP
.fi
.RE
.sp
.LP
The \fBi\fP command shall insert the given text before the addressed
line; the current line is set to the last inserted line
or, if there was none, to the addressed line. This command differs
from the \fBa\fP command only in the placement of the input
text. Address 0 shall be valid for this command; it shall be interpreted
as if address 1 were specified.
.SS Join Command
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB(.,.+1)j
\fP
.fi
.RE
.sp
.LP
The \fBj\fP command shall join contiguous lines by removing the appropriate
<newline>s. If exactly one address is given,
this command shall do nothing. If lines are joined, the current line
number shall be set to the address of the joined line;
otherwise, the current line number shall be unchanged.
.SS Mark Command
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB(.)k\fP\fIx\fP
.fi
.RE
.sp
.LP
The \fBk\fP command shall mark the addressed line with name \fIx\fP,
which the application shall ensure is a lowercase letter
from the portable character set. The address \fB"'x"\fP shall then
refer to this line; the current line number shall be
unchanged.
.SS List Command
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB(.,.)l
\fP
.fi
.RE
.sp
.LP
The \fBl\fP command shall write to standard output the addressed lines
in a visually unambiguous form. The characters listed in
the Base Definitions volume of IEEE\ Std\ 1003.1-2001, Table 5-1,
Escape Sequences and Associated Actions ( \fB'\\\\'\fP ,
\fB'\\a'\fP , \fB'\\b'\fP , \fB'\\f'\fP , \fB'\\r'\fP , \fB'\\t'\fP
, \fB'\\v'\fP ) shall be written as the
corresponding escape sequence; the \fB'\\n'\fP in that table is not
applicable. Non-printable characters not in the table shall
be written as one three-digit octal number (with a preceding backslash
character) for each byte in the character (most significant
byte first). If the size of a byte on the system is greater than nine
bits, the format used for non-printable characters is
implementation-defined.
.LP
Long lines shall be folded, with the point of folding indicated by
<newline> preceded by a backslash; the length at which
folding occurs is unspecified, but should be appropriate for the output
device. The end of each line shall be marked with a
\fB'$'\fP , and \fB'$'\fP characters within the text shall be written
with a preceding backslash. An \fBl\fP command can be
appended to any other command other than \fBe\fP, \fBE\fP, \fBf\fP,
\fBq\fP, \fBQ\fP, \fBr\fP, \fBw\fP, or \fB!\fP. The
current line number shall be set to the address of the last line written.
.SS Move Command
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB(.,.)m\fP\fIaddress\fP
.fi
.RE
.sp
.LP
The \fBm\fP command shall reposition the addressed lines after the
line addressed by \fIaddress\fP. Address 0 shall be valid
for \fIaddress\fP and cause the addressed lines to be moved to the
beginning of the buffer. It shall be an error if address
\fIaddress\fP falls within the range of moved lines. The current line
number shall be set to the address of the last line
moved.
.SS Number Command
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB(.,.)n
\fP
.fi
.RE
.sp
.LP
The \fBn\fP command shall write to standard output the addressed lines,
preceding each line by its line number and a
<tab>; the current line number shall be set to the address of the
last line written. The \fBn\fP command can be appended to
any command other than \fBe\fP, \fBE\fP, \fBf\fP, \fBq\fP, \fBQ\fP,
\fBr\fP, \fBw\fP, or \fB!\fP.
.SS Print Command
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB(.,.)p
\fP
.fi
.RE
.sp
.LP
The \fBp\fP command shall write to standard output the addressed lines;
the current line number shall be set to the address of
the last line written. The \fBp\fP command can be appended to any
command other than \fBe\fP, \fBE\fP, \fBf\fP, \fBq\fP,
\fBQ\fP, \fBr\fP, \fBw\fP, or \fB!\fP.
.SS Prompt Command
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fBP
\fP
.fi
.RE
.sp
.LP
The \fBP\fP command shall cause \fIed\fP to prompt with an asterisk
( \fB'*'\fP ) (or \fIstring\fP, if \fB-p\fP is
specified) for all subsequent commands. The \fBP\fP command alternatively
shall turn this mode on and off; it shall be initially
on if the \fB-p\fP option is specified; otherwise, off. The current
line number shall be unchanged.
.SS Quit Command
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fBq
\fP
.fi
.RE
.sp
.LP
The \fBq\fP command shall cause \fIed\fP to exit. If the buffer has
changed since the last time the entire buffer was written,
the user shall be warned, as described previously.
.SS Quit Without Checking Command
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fBQ
\fP
.fi
.RE
.sp
.LP
The \fBQ\fP command shall cause \fIed\fP to exit without checking
whether changes have been made in the buffer since the last
\fBw\fP command.
.SS Read Command
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB($)r\fP \fB[\fP\fIfile\fP\fB]\fP
.fi
.RE
.sp
.LP
The \fBr\fP command shall read in the file named by the pathname \fIfile\fP
and append it after the addressed line. If no
\fIfile\fP argument is given, the currently remembered pathname, if
any, shall be used (see the \fBe\fP and \fBf\fP commands).
The currently remembered pathname shall not be changed unless there
is no remembered pathname. Address 0 shall be valid for
\fBr\fP and shall cause the file to be read at the beginning of the
buffer. If the read is successful, and \fB-s\fP was not
specified, the number of bytes read shall be written to standard output
in the following format:
.sp
.RS
.nf

\fB"%d\\n", <\fP\fInumber of bytes read\fP\fB>
\fP
.fi
.RE
.LP
The current line number shall be set to the address of the last line
read in. If \fIfile\fP is replaced by \fB'!'\fP , the
rest of the line shall be taken to be a shell command line whose output
is to be read. Such a shell command line shall not be
remembered as the current pathname.
.SS Substitute Command
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB(.,.)s/\fP\fIRE\fP\fB/\fP\fIreplacement\fP\fB/\fP\fIflags\fP
.fi
.RE
.sp
.LP
The \fBs\fP command shall search each addressed line for an occurrence
of the specified RE and replace either the first or all
(non-overlapped) matched strings with the \fIreplacement\fP; see the
following description of the \fBg\fP suffix. It is an error
if the substitution fails on every addressed line. Any character other
than <space> or <newline> can be used instead of
a slash to delimit the RE and the replacement. Within the RE, the
RE delimiter itself can be used as a literal character if it is
preceded by a backslash. The current line shall be set to the address
of the last line on which a substitution occurred.
.LP
An ampersand ( \fB'&'\fP ) appearing in the \fIreplacement\fP shall
be replaced by the string matching the RE on the
current line. The special meaning of \fB'&'\fP in this context can
be suppressed by preceding it by backslash. As a more
general feature, the characters \fB'\\n'\fP , where \fIn\fP is a digit,
shall be replaced by the text matched by the
corresponding back-reference expression. When the character \fB'%'\fP
is the only character in the \fIreplacement\fP, the
\fIreplacement\fP used in the most recent substitute command shall
be used as the \fIreplacement\fP in the current substitute
command; if there was no previous substitute command, the use of \fB'%'\fP
in this manner shall be an error. The \fB'%'\fP
shall lose its special meaning when it is in a replacement string
of more than one character or is preceded by a backslash. For
each backslash ( \fB'\\'\fP ) encountered in scanning \fIreplacement\fP
from beginning to end, the following character shall
lose its special meaning (if any). It is unspecified what special
meaning is given to any character other than \fB'&'\fP ,
\fB'\\'\fP , \fB'%'\fP , or digits.
.LP
A line can be split by substituting a <newline> into it. The application
shall ensure it escapes the <newline> in
the \fIreplacement\fP by preceding it by backslash. Such substitution
cannot be done as part of a \fBg\fP or \fBv\fP \fIcommand
list\fP. The current line number shall be set to the address of the
last line on which a substitution is performed. If no
substitution is performed, the current line number shall be unchanged.
If a line is split, a substitution shall be considered to
have been performed on each of the new lines for the purpose of determining
the new current line number. A substitution shall be
considered to have been performed even if the replacement string is
identical to the string that it replaces.
.LP
The application shall ensure that the value of \fIflags\fP is zero
or more of:
.TP 7
\fIcount\fP
Substitute for the \fIcount\fPth occurrence only of the RE found on
each addressed line.
.TP 7
\fBg\fP
Globally substitute for all non-overlapping instances of the RE rather
than just the first one. If both \fBg\fP and
\fIcount\fP are specified, the results are unspecified.
.TP 7
\fBl\fP
Write to standard output the final line in which a substitution was
made. The line shall be written in the format specified for
the \fBl\fP command.
.TP 7
\fBn\fP
Write to standard output the final line in which a substitution was
made. The line shall be written in the format specified for
the \fBn\fP command.
.TP 7
\fBp\fP
Write to standard output the final line in which a substitution was
made. The line shall be written in the format specified for
the \fBp\fP command.
.sp
.SS Copy Command
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB(.,.)t\fP\fIaddress\fP
.fi
.RE
.sp
.LP
The \fBt\fP command shall be equivalent to the \fBm\fP command, except
that a copy of the addressed lines shall be placed
after address \fIaddress\fP (which can be 0); the current line number
shall be set to the address of the last line added.
.SS Undo Command
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fBu
\fP
.fi
.RE
.sp
.LP
The \fBu\fP command shall nullify the effect of the most recent command
that modified anything in the buffer, namely the most
recent \fBa\fP, \fBc\fP, \fBd\fP, \fBg\fP, \fBi\fP, \fBj\fP, \fBm\fP,
\fBr\fP, \fBs\fP, \fBt\fP, \fBu\fP, \fBv\fP,
\fBG\fP, or \fBV\fP command. All changes made to the buffer by a \fBg\fP,
\fBG\fP, \fBv\fP, or \fBV\fP global command shall
be undone as a single change; if no changes were made by the global
command (such as with \fBg\fP/RE/ \fBp\fP), the \fBu\fP
command shall have no effect. The current line number shall be set
to the value it had immediately before the command being undone
started.
.SS Global Non-Matched Command
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB(1,$)v/\fP\fIRE\fP\fB/\fP\fIcommand list\fP
.fi
.RE
.sp
.LP
This command shall be equivalent to the global command \fBg\fP except
that the lines that are marked during the first step
shall be those for which the line excluding the terminating <newline>
does not match the RE.
.SS Interactive Global Not-Matched Command
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB(1,$)V/\fP\fIRE\fP\fB/
\fP
.fi
.RE
.sp
.LP
This command shall be equivalent to the interactive global command
\fBG\fP except that the lines that are marked during the
first step shall be those for which the line excluding the terminating
<newline> does not match the RE.
.SS Write Command
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB(1,$)w\fP \fB[\fP\fIfile\fP\fB]
\fP
.fi
.RE
.sp
.LP
The \fBw\fP command shall write the addressed lines into the file
named by the pathname \fIfile\fP. The command shall create
the file, if it does not exist, or shall replace the contents of the
existing file. The currently remembered pathname shall not be
changed unless there is no remembered pathname. If no pathname is
given, the currently remembered pathname, if any, shall be used
(see the \fBe\fP and \fBf\fP commands); the current line number shall
be unchanged. If the command is successful, the number of
bytes written shall be written to standard output, unless the \fB-s\fP
option was specified, in the following format:
.sp
.RS
.nf

\fB"%d\\n", <\fP\fInumber of bytes written\fP\fB>
\fP
.fi
.RE
.LP
If \fIfile\fP begins with \fB'!'\fP , the rest of the line shall be
taken to be a shell command line whose standard input
shall be the addressed lines. Such a shell command line shall not
be remembered as the current pathname. This usage of the write
command with \fB'!'\fP shall not be considered as a "last \fBw\fP
command that wrote the entire buffer", as described
previously; thus, this alone shall not prevent the warning to the
user if an attempt is made to destroy the editor buffer via the
\fBe\fP or \fBq\fP commands.
.SS Line Number Command
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB($)=
\fP
.fi
.RE
.sp
.LP
The line number of the addressed line shall be written to standard
output in the following format:
.sp
.RS
.nf

\fB"%d\\n", <\fP\fIline number\fP\fB>
\fP
.fi
.RE
.LP
The current line number shall be unchanged by this command.
.SS Shell Escape Command
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB!\fP\fIcommand\fP
.fi
.RE
.sp
.LP
The remainder of the line after the \fB'!'\fP shall be sent to the
command interpreter to be interpreted as a shell command
line. Within the text of that shell command line, the unescaped character
\fB'%'\fP shall be replaced with the remembered
pathname; if a \fB'!'\fP appears as the first character of the command,
it shall be replaced with the text of the previous shell
command executed via \fB'!'\fP . Thus, \fB"!!"\fP shall repeat the
previous !\fIcommand\fP. If any replacements of
\fB'%'\fP or \fB'!'\fP are performed, the modified line shall be written
to the standard output before \fIcommand\fP is
executed. The \fB!\fP command shall write:
.sp
.RS
.nf

\fB"!\\n"
\fP
.fi
.RE
.LP
to standard output upon completion, unless the \fB-s\fP option is
specified. The current line number shall be unchanged.
.SS Null Command
.TP 7
\fISynopsis\fP:
.sp
.RS
.nf

\fB(.+1)
\fP
.fi
.RE
.sp
.LP
An address alone on a line shall cause the addressed line to be written.
A <newline> alone shall be equivalent to
\fB"+1p"\fP . The current line number shall be set to the address
of the written line.
.SH EXIT STATUS
.LP
The following exit values shall be returned:
.TP 7
\ 0
Successful completion without any file or command errors.
.TP 7
>0
An error occurred.
.sp
.SH CONSEQUENCES OF ERRORS
.LP
When an error in the input script is encountered, or when an error
is detected that is a consequence of the data (not) present
in the file or due to an external condition such as a read or write
error:
.IP " *" 3
If the standard input is a terminal device file, all input shall be
flushed, and a new command read.
.LP
.IP " *" 3
If the standard input is a regular file, \fIed\fP shall terminate
with a non-zero exit status.
.LP
.LP
\fIThe following sections are informative.\fP
.SH APPLICATION USAGE
.LP
Because of the extremely terse nature of the default error messages,
the prudent script writer begins the \fIed\fP input
commands with an \fBH\fP command, so that if any errors do occur at
least some clue as to the cause is made available.
.LP
In previous versions, an obsolescent \fB-\fP option was described.
This is no longer specified. Applications should use the
\fB-s\fP option. Using \fB-\fP as a \fIfile\fP operand now produces
unspecified results. This allows implementations to continue
to support the former required behavior.
.SH EXAMPLES
.LP
None.
.SH RATIONALE
.LP
The initial description of this utility was adapted from the SVID.
It contains some features not found in Version 7 or
BSD-derived systems. Some of the differences between the POSIX and
BSD \fIed\fP utilities include, but need not be limited to:
.IP " *" 3
The BSD \fB-\fP option does not suppress the \fB'!'\fP prompt after
a \fB!\fP command.
.LP
.IP " *" 3
BSD does not support the special meanings of the \fB'%'\fP and \fB'!'\fP
characters within a \fB!\fP command.
.LP
.IP " *" 3
BSD does not support the \fIaddresses\fP \fB';'\fP and \fB','\fP .
.LP
.IP " *" 3
BSD allows the command/suffix pairs \fBpp\fP, \fBll\fP, and so on,
which are unspecified in this volume of
IEEE\ Std\ 1003.1-2001.
.LP
.IP " *" 3
BSD does not support the \fB'!'\fP character part of the \fBe\fP,
\fBr\fP, or \fBw\fP commands.
.LP
.IP " *" 3
A failed \fBg\fP command in BSD sets the line number to the last line
searched if there are no matches.
.LP
.IP " *" 3
BSD does not default the \fIcommand list\fP to the \fBp\fP command.
.LP
.IP " *" 3
BSD does not support the \fBG\fP, \fBh\fP, \fBH\fP, \fBn\fP, or \fBV\fP
commands.
.LP
.IP " *" 3
On BSD, if there is no inserted text, the insert command changes the
current line to the referenced line -1; that is, the line
before the specified line.
.LP
.IP " *" 3
On BSD, the \fIjoin\fP command with only a single address changes
the current line to that
address.
.LP
.IP " *" 3
BSD does not support the \fBP\fP command; moreover, in BSD it is synonymous
with the \fBp\fP command.
.LP
.IP " *" 3
BSD does not support the \fIundo\fP of the commands \fBj\fP, \fBm\fP,
\fBr\fP, \fBs\fP, or \fBt\fP.
.LP
.IP " *" 3
The Version 7 \fIed\fP command \fBW\fP, and the BSD \fIed\fP commands
\fBW\fP, \fBwq\fP, and \fBz\fP are not present in
this volume of IEEE\ Std\ 1003.1-2001.
.LP
.LP
The \fB-s\fP option was added to allow the functionality of the now
withdrawn \fB-\fP option in a manner compatible with the
Utility Syntax Guidelines.
.LP
In early proposals there was a limit, {ED_FILE_MAX}, that described
the historical limitations of some \fIed\fP utilities in
their handling of large files; some of these have had problems with
files larger than 100000 bytes. It was this limitation that
prompted much of the desire to include a \fIsplit\fP command in this
volume of
IEEE\ Std\ 1003.1-2001. Since this limit was removed, this volume
of IEEE\ Std\ 1003.1-2001 requires that
implementations document the file size limits imposed by \fIed\fP
in the conformance document. The limit {ED_LINE_MAX} was also
removed; therefore, the global limit {LINE_MAX} is used for input
and output lines.
.LP
The manner in which the \fBl\fP command writes non-printable characters
was changed to avoid the historical
backspace-overstrike method. On video display terminals, the overstrike
is ambiguous because most terminals simply replace
overstruck characters, making the \fBl\fP format not useful for its
intended purpose of unambiguously understanding the content of
the line. The historical backslash escapes were also ambiguous. (The
string \fB"a\\0011"\fP could represent a line containing
those six characters or a line containing the three characters \fB'a'\fP
, a byte with a binary value of 1, and a 1.) In the
format required here, a backslash appearing in the line is written
as \fB"\\\\"\fP so that the output is truly unambiguous. The
method of marking the ends of lines was adopted from the \fIex\fP
editor and is required for
any line ending in <space>s; the \fB'$'\fP is placed on all lines
so that a real \fB'$'\fP at the end of a line cannot
be misinterpreted.
.LP
Systems with bytes too large to fit into three octal digits must devise
other means of displaying non-printable characters.
Consideration was given to requiring that the number of octal digits
be large enough to hold a byte, but this seemed to be too
confusing for applications on the vast majority of systems where three
digits are adequate. It would be theoretically possible for
the application to use the \fIgetconf\fP utility to find out the CHAR_BIT
value and deal
with such an algorithm; however, there is really no portable way that
an application can use the octal values of the bytes across
various coded character sets, so the additional specification was
not worthwhile.
.LP
The description of how a NUL is written was removed. The NUL character
cannot be in text files, and this volume of
IEEE\ Std\ 1003.1-2001 should not dictate behavior in the case of
undefined, erroneous input.
.LP
Unlike some of the other editing utilities, the filenames accepted
by the \fBE\fP, \fBe\fP, \fBR\fP, and \fBr\fP commands
are not patterns.
.LP
Early proposals stated that the \fB-p\fP option worked only when standard
input was associated with a terminal device. This has
been changed to conform to historical implementations, thereby allowing
applications to interpose themselves between a user and the
\fIed\fP utility.
.LP
The form of the substitute command that uses the \fBn\fP suffix was
limited in some historical documentation (where this was
described incorrectly as "backreferencing"). This limit has been omitted
because there is no reason why an editor processing
lines of {LINE_MAX} length should have this restriction. The command
\fBs/x/X/2047\fP should be able to substitute the 2047th
occurrence of \fB'x'\fP on a line.
.LP
The use of printing commands with printing suffixes (such as \fBpn\fP,
\fBlp\fP, and so on) was made unspecified because
BSD-based systems allow this, whereas System V does not.
.LP
Some BSD-based systems exit immediately upon receipt of end-of-file
if all of the lines in the file have been deleted. Since
this volume of IEEE\ Std\ 1003.1-2001 refers to the \fBq\fP command
in this instance, such behavior is not allowed.
.LP
Some historical implementations returned exit status zero even if
command errors had occurred; this is not allowed by this
volume of IEEE\ Std\ 1003.1-2001.
.LP
Some historical implementations contained a bug that allowed a single
period to be entered in input mode as <backslash>
<period> <newline>. This is not allowed by \fIed\fP because there
is no description of escaping any of the characters
in input mode; backslashes are entered into the buffer exactly as
typed. The typical method of entering a single period has been to
precede it with another character and then use the substitute command
to delete that character.
.LP
It is difficult under some modes of some versions of historical operating
system terminal drivers to distinguish between an
end-of-file condition and terminal disconnect. IEEE\ Std\ 1003.1-2001
does not require implementations to distinguish
between the two situations, which permits historical implementations
of the \fIed\fP utility on historical platforms to conform.
Implementations are encouraged to distinguish between the two, if
possible, and take appropriate action on terminal disconnect.
.LP
Historically, \fIed\fP accepted a zero address for the \fBa\fP and
\fBr\fP commands in order to insert text at the start of
the edit buffer. When the buffer was empty the command \fB.=\fP returned
zero. IEEE\ Std\ 1003.1-2001 requires conformance
to historical practice.
.LP
For consistency with the \fBa\fP and \fBr\fP commands and better user
functionality, the \fBi\fP and \fBc\fP commands must
also accept an address of 0, in which case 0\fIi\fP is treated as
1\fIi\fP and likewise for the \fBc\fP command.
.LP
All of the following are valid addresses:
.TP 7
\fB+++\fP
Three lines after the current line.
.TP 7
\fB/\fP\fIpattern\fP\fB/-\fP
One line before the next occurrence of pattern.
.TP 7
\fB-2\fP
Two lines before the current line.
.TP 7
\fB3\ ----\ 2\fP
Line one (note the intermediate negative address).
.TP 7
\fB1\ 2\ 3\fP
Line six.
.sp
.LP
Any number of addresses can be provided to commands taking addresses;
for example, \fB"1,2,3,4,5p"\fP prints lines 4 and 5,
because two is the greatest valid number of addresses accepted by
the \fBprint\fP command. This, in combination with the semicolon
delimiter, permits users to create commands based on ordered patterns
in the file. For example, the command \fB"3;/foo/;+2p"\fP
will display the first line after line 3 that contains the pattern
\fIfoo\fP, plus the next two lines. Note that the address
\fB"3;"\fP must still be evaluated before being discarded, because
the search origin for the \fB"/foo/"\fP command depends on
this.
.LP
Historically, \fIed\fP disallowed address chains, as discussed above,
consisting solely of comma or semicolon separators; for
example, \fB",,,"\fP or \fB";;;"\fP were considered an error. For
consistency of address specification, this restriction is
removed. The following table lists some of the address forms now possible:
.TS C
center; l2 l2 l2 l2 l.
\fBAddress\fP	\fBAddr1\fP	\fBAddr2\fP	\fBStatus\fP	\fBComment\fP
7,	7	7	Historical	\ 
7,5,	5	5	Historical	\ 
7,5,9	5	9	Historical	\ 
7,9	7	9	Historical	\ 
7,+	7	8	Historical	\ 
,	1	$	Historical	\ 
,7	1	7	Extension	\ 
,,	$	$	Extension	\ 
,;	$	$	Extension	\ 
7;	7	7	Historical	\ 
7;5;	5	5	Historical	\ 
7;5;9	5	9	Historical	\ 
7;5,9	5	9	Historical	\ 
7;$;4	$	4	Historical	Valid, but erroneous.
7;9	7	9	Historical	\ 
7;+	7	8	Historical	\ 
;	.	$	Historical	\ 
;7	.	7	Extension	\ 
;;	$	$	Extension	\ 
;,	$	$	Extension	\ 
.TE
.LP
Historically, values could be added to addresses by including them
after one or more <blank>s; for example,
\fB"3\ -\ 5p"\fP wrote the seventh line of the file, and \fB"/foo/\ 5"\fP
was the same as \fB"5\ /foo/"\fP
\&. However, only absolute values could be added; for example, \fB"5\ /foo/"\fP
was an error. IEEE\ Std\ 1003.1-2001
requires conformance to historical practice.
.LP
Historically, \fIed\fP accepted the \fB'^'\fP character as an address,
in which case it was identical to the hyphen
character. IEEE\ Std\ 1003.1-2001 does not require or prohibit this
behavior.
.SH FUTURE DIRECTIONS
.LP
None.
.SH SEE ALSO
.LP
\fIUtility Description Defaults\fP , \fIex\fP , \fIsed\fP , \fIsh\fP
, \fIvi\fP
.SH COPYRIGHT
Portions of this text are reprinted and reproduced in electronic form
from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
-- Portable Operating System Interface (POSIX), The Open Group Base
Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
Electrical and Electronics Engineers, Inc and The Open Group. In the
event of any discrepancy between this version and the original IEEE and
The Open Group Standard, the original IEEE and The Open Group Standard
is the referee document. The original Standard can be obtained online at
http://www.opengroup.org/unix/online.html .