-
Notifications
You must be signed in to change notification settings - Fork 6
/
sed.html
711 lines (656 loc) · 27.7 KB
/
sed.html
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>sed.py</title>
<meta http-equiv="Content-Language" content="en-us" />
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii" />
<meta name="description" content="python sed" />
<meta name="keywords" content="sed, python, pythonsed, regexp" />
<style type="text/css">
body {
margin-top:0.5in;
margin-right:0.8in;
margin-bottom:0.5in;
margin-left:1.3in;
font-family:arial;
font-size:10pt;
}
pre, h1, h2, h3, h4, code.blue { color:#0B5394; }
h1 { text-align:left; margin-top:10mm; margin-bottom:0; }
h2 { text-align:left; font-size:larger; margin-top:0; margin-bottom:5mm; }
p.contents { font-size:105%; margin-top:0; margin-left:0; margin-bottom:0; margin-right:0; }
p.contents-top { font-size:105%; margin-left:0; margin-bottom:0; margin-right:0; }
p.contents-bot { font-size:105%; margin-top:0; margin-left:0; margin-right:0; }
a.contents:link, a.contents:visited { color:#0B5394; text-decoration:none; }
a.contents:hover { color:#000000; text-decoration:none; }
a:link, a:visited { color:#0B5394; text-decoration:none; }
a:hover { color:#000000; text-decoration:none; }
code.title { font-size:larger; font-weight:bold; margin-top:0;
line-height: 2px; margin-bottom:0px; }
hr { margin-left:-0.4in }
hr.light { color:#C0C0C0; margin-bottom:20px; }
div.term { display: inline-block; width: 80pt; }
div.descr { display: inline-block; }
ul { margin-left:0.15in; padding-left:0px; }
table.framed{ border-collapse: collapse; border-spacing: 0; }
td.framed{ border: 1px solid #C0C0C0; border-width:1px; }
</style>
</head>
<body>
<h1>sed.py</h1>
<h2>A full implementation of sed in Python</h2>
<hr />
<h3 id="Contents">Contents</h3>
<hr size="1" color="#C0C0C0" />
<p style="font-size:1px"> </p>
<p class="contents-top">
<a class="contents" href="#GeneralInformation">General Information</a></p>
<p class="contents">
<a class="contents" href="#UsageConsole">Usage as a command line utility</a></p>
<p class="contents">
<a class="contents" href="#UsageModule">Usage as a Python module</a></p>
<p class="contents">
<a class="contents" href="#Dialect">Sed dialect</a></p>
<p class="contents">
<a class="contents" href="#Testing">Testing</a></p>
<p class="contents">
<a class="contents" href="#Timing">Timing</a></p>
<p class="contents-bot">
<a class="contents" href="#Todo">To do list</a></p>
<p style="font-size:1px"> </p>
<hr id="GeneralInformation" />
<h3>General Information</h3>
<hr size="1" color="#C0C0C0" />
<h4>Description</h4>
<p>
<code class=blue>sed.py</code> is a full and working Python
implementation of sed. Its reference is GNU sed 4.2 of which it
implements almost all commands and features. It may be used as a command
line utility or it can be used as a module to bring sed functionality
to Python scripts.
</p>
<p>
A complete set of tests is available as well as a testing utility. These
tests include scripts from various origins and cover all aspects of sed
functionalities.
</p>
<p style="font-size:1px"> </p>
<hr size="1" color="#C0C0C0" />
<h4>Platform</h4>
<p>
<code class=blue>sed.py</code> is a Python script and should run on any
platform where a recent version of Python is installed.
</p>
<p>
Detailed compatibility status:
</p>
<dl>
<dt>Python 3</dt>
<dd>Fully compatible</dd>
<dt>Python 2.7.4 and above</dt>
<dd>Fully compatible</dd>
<dt>Python 2.7 to Python 2.7.3</dt>
<dd>Fully compatible except regexps of the form ((.*)*). This causes
one of the script from Chang suite to fail.</dd>
<dt>Python 2.6</dt>
<dd>Fully compatible except regexps of the form ((.*)*). argparse module
must be installed.</dd>
<dt>Python 2.5 and below</dt>
<dd>Not tested</dd>
</dl>
<p>
Compatibility status applies also to the testing utility <code
class=blue>test-suite.py</code>.
</p>
<p style="font-size:1px"> </p>
<hr size="1" color="#C0C0C0" />
<h4>License</h4>
<p>
<code class=blue>sed.py</code> is released under the MIT license.
</p>
<p style="font-size:1px"> </p>
<hr size="1" color="#C0C0C0" />
<h4>Links and contact</h4>
<ul>
<li><a href="pythonsed-1.00.zip">Download sed.py and help page</a></li>
<li><a href="pythonsed-tests-1.00.zip">Download testing script and test suites</a></li>
<li><a href="https://github.com/GillesArcas/PythonSed">Repository</a></li>
<li>Mail to: gilles dot arcas at gmail dot com</li>
<li><a href="http://www.godrago.net/PersonalHub.html">Personal hub</a></li>
</ul>
<p style="font-size:1px"> </p>
<hr id="UsageConsole"/>
<h3>Usage as a command line utility</h3>
<hr size="1" color="#C0C0C0" />
<p style="font-size:1px"> </p>
<p>
<code class=blue>sed.py</code> may be used as console program receiving
information from the command line. The format of the command line is:
</p>
<pre>sed.py [options] -e<script expression> <input text file>
sed.py [options] -f<script file> <input text file></pre>
<p>
Note that <code class=blue>sed.py</code> accepts only one script file or expression, and only one input file.
<code class=blue>options</code> may be one or both of:
</p>
<table>
<tr>
<td width=50><code class=blue>-n</code></td><td>disable automatic
printing</td>
</tr>
<tr>
<td width=50><code class=blue>-r</code></td><td>use extended regular
expressions</td>
</tr>
</table>
<p>
<code class=blue>sed.py</code> may also use redirection to receive its
input or send its output with the usual syntax:
</p>
<pre>cat myfile | sed.py -f myscript1 | sed.py -f myscript2 > myresultfile</pre>
<p>
It is also possible for <code class=blue>sed.py</code> to receive its
input from the keyboard by omitting any input file:
</p>
<pre>sed.py -f myscript</pre>
<p>
It is a Windows command line limitation that redirection does not work
when calling directly a python script on the command line (check<a
href="https://mail.python.org/pipermail/python-bugs-list/2004-August/024920.html">
this</a> for explanation).
In that case, it is required to explicitly call python. Assuming python
is in the path:
</p>
<pre>> type myfile | python sed.py -f myscript > myresultfile</pre>
<p>
It is also possible to hide the call in a batch file and even call it
without any extension:
</p>
<pre>> type sed.bat
python sed.py %1 %2 %3 %4 %5
> type myfile | sed -f myscript > myresultfile
...</pre>
<p style="font-size:4px"> </p>
<hr id="UsageModule"/>
<h3>Usage as a Python module</h3>
<hr size="1" color="#C0C0C0" />
<p style="font-size:1px"> </p>
<p>
An example covering all necessary symbols:
</p>
<pre>
from sed import Sed, SedException
sed = Sed()
try:
sed.no_autoprint = True
sed.regexp_extended = False
sed.load_script('myscript.sed')
sed.apply('myinput.txt')
except SedException as e:
print e.message
except:
raise</pre>
<p>
Note that <code class=blue>sed.apply()</code> returns the list of lines
printed by the script. As a default, these lines are printed to stdout.
<code class=blue>sed.apply()</code> has an output parameter which
enables to inhibit printing the lines (<code
class=blue>output=None</code>) or enables to redirect the output to some
text file (<code class=blue>output=somefile.txt</code>).
</p>
<p>
The script may also be read from a string by using <code
class=blue>sed.load_string(my_script_string)</code>.
</p>
<p style="font-size:1px"> </p>
<hr id="Dialect" />
<h3>sed dialect</h3>
<hr size="1" color="#C0C0C0" />
<p>
<code class=blue>sed.py</code> implements all standard commands and
regular expression features of sed. Its reference is GNU sed 4.2. It
implements almost all its features except the most specific ones.
</p>
<p>
GNU sed <a
href="http://www.gnu.org/software/sed/manual/sed.html">manual</a> page
can serve as a reference for <code class=blue>sed.py</code> given the
differences described in the following.
</p>
<p style="font-size:1px"> </p>
<hr size="1" color="#C0C0C0" />
<h4>Addresses</h4>
<table>
<tr>
<td width=150><code>number</code></td><td>standard behavior</td>
</tr>
<tr>
<td><code>$</code></td><td>standard behavior</td>
</tr>
<tr>
<td><code>/regexp/</code></td><td>standard behavior</td>
</tr>
<tr>
<td><code>/regexp/I</code></td><td>implemented</td>
</tr>
<tr>
<td><code>\%regexp%</code></td><td>standard behavior</td>
</tr>
<tr>
<td><code>address,address</code></td><td>standard behavior</td>
</tr>
<tr>
<td><code>address!</code></td><td>standard behavior</td>
</tr>
<tr>
<td><code>0,/regexp/</code></td><td>not implemented</td>
</tr>
<tr>
<td><code>first~step</code></td><td>not implemented</td>
</tr>
<tr>
<td><code>addr1,+N</code></td><td>not implemented</td>
</tr>
<tr>
<td><code>addr1,~N</code></td><td>not implemented</td>
</tr>
</table>
<p style="font-size:1px"> </p>
<hr size="1" color="#C0C0C0" />
<h4>Regular expressions</h4>
<table>
<tr>
<td><code width=150>char</code></td><td>standard behavior</td>
</tr>
<tr>
<td><code>*</code></td><td>standard behavior</td>
</tr>
<tr>
<td><code>\+</code></td><td>standard behavior</td>
</tr>
<tr>
<td><code>\?</code></td><td>standard behavior</td>
</tr>
<tr>
<td><code>\{i\} \{i,j} \{i,\}</code></td><td>standard behavior</td>
</tr>
<tr>
<td><code>\(regexp\)</code></td><td>standard behavior</td>
</tr>
<tr>
<td><code>.</code></td><td>standard behavior</td>
</tr>
<tr>
<td><code>^</code></td><td>standard behavior. When not at start of
regexp, matches as itself</td>
</tr>
<tr>
<td><code>$</code></td><td>standard behavior. When not at end of
regexp, matches as itself</td>
</tr>
<tr>
<td><code>[list] [^list]</code></td><td>standard behavior. [.ch.],
[=a=], [:space:] are not implemented</td>
</tr>
<tr>
<td><code>regexp1\|regexp2</code></td><td>standard behavior</td>
</tr>
<tr>
<td><code>regexp1regexp2</code></td><td>standard behavior</td>
</tr>
<tr>
<td><code>\digit</code></td><td>standard behavior (back
reference)</td>
</tr>
<tr>
<td><code>\n \t</code></td><td>standard behavior (extensions \s\S
etc. are not handled)</td>
</tr>
<tr>
<td><code>\char</code></td><td>standard behavior (disable special
regexp characters)</td>
</tr>
</table>
<p>
Note that for any combination of quantifiers (*, +, ?, {}), consecutive
quantifiers or a quantifier starting a regexp will launch an error. This
is true in basic or extended regular expression modes.
</p>
<p style="font-size:1px"> </p>
<hr size="1" color="#C0C0C0" />
<h4>Extended regular expressions</h4>
<p>
Using the -r switch enables to simplify regular expressions by removing
the antislah character before the special characters +, ?, (, ), |, { and }.
If these characters must appear as regular characters in a regexp, they
must be slashed.
</p>
<p style="font-size:1px"> </p>
<hr size="1" color="#C0C0C0" />
<h4>Commands</h4>
<table>
<tr>
<td width=150><code>a\<br/>
text</code></td><td width=250>Compliant with <a href="https://www.gnu.org/software/sed/manual/html_node/Other-Commands.html#Other-Commands">GNU sed description</a></td><td width=500>
(including one liner syntax and double address extensions)</td>
</tr>
<tr>
<td><code>b label</code></td><td>Compliant with <a href="https://www.gnu.org/software/sed/manual/html_node/Programming-Commands.html#Programming-Commands">GNU sed description</a></td>
</tr>
<tr>
<td><code>: label</code></td><td>Compliant with <a href="https://www.gnu.org/software/sed/manual/html_node/Programming-Commands.html#Programming-Commands">GNU sed description</a></td>
</tr>
<tr>
<td><code>c\<br/>
text</code></td><td>Compliant with <a href="https://www.gnu.org/software/sed/manual/html_node/Other-Commands.html#Other-Commands">GNU sed description</a>
</td><td>(including single line and double address extensions)</td>
</tr>
<tr>
<td><code>d</code></td><td>Compliant with <a href="https://www.gnu.org/software/sed/manual/html_node/Common-Commands.html#Common-Commands">GNU sed description</a></td>
</tr>
<tr>
<td><code>D</code></td><td>Compliant with <a href="https://www.gnu.org/software/sed/manual/html_node/Other-Commands.html#Other-Commands">GNU sed description</a></td>
</tr>
<tr>
<td><code>=</code></td><td>Compliant with <a href="https://www.gnu.org/software/sed/manual/html_node/Other-Commands.html#Other-Commands">GNU sed description</a>
</td><td>(including double address extension)</td>
</tr>
<tr>
<td><code>g</code></td><td>Compliant with <a href="https://www.gnu.org/software/sed/manual/html_node/Other-Commands.html#Other-Commands">GNU sed description</a></td>
</tr>
<tr>
<td><code>G</code></td><td>Compliant with <a href="https://www.gnu.org/software/sed/manual/html_node/Other-Commands.html#Other-Commands">GNU sed description</a></td>
</tr>
<tr>
<td><code>h</code></td><td>Compliant with <a href="https://www.gnu.org/software/sed/manual/html_node/Other-Commands.html#Other-Commands">GNU sed description</a></td>
</tr>
<tr>
<td><code>H</code></td><td>Compliant with <a href="https://www.gnu.org/software/sed/manual/html_node/Other-Commands.html#Other-Commands">GNU sed description</a></td>
</tr>
<tr>
<td><code>i\<br/>
text</code></td><td>Compliant with <a href="https://www.gnu.org/software/sed/manual/html_node/Other-Commands.html#Other-Commands">GNU sed description</a>
</td><td>(including single line and double address extensions)</td>
</tr>
<tr>
<td><code>l</code></td><td>Compliant with <a href="https://www.gnu.org/software/sed/manual/html_node/Other-Commands.html#Other-Commands">GNU sed description</a>
</td><td>(length parameter not implemented)</td>
</tr>
<tr>
<td><code>n</code></td><td>Compliant with <a href="https://www.gnu.org/software/sed/manual/html_node/Common-Commands.html#Common-Commands">GNU sed description</a></td>
</tr>
<tr>
<td><code>N</code></td><td>Compliant with <a href="https://www.gnu.org/software/sed/manual/html_node/Other-Commands.html#Other-Commands">GNU sed description</a></td>
</tr>
<tr>
<td><code>p</code></td><td>Compliant with <a href="https://www.gnu.org/software/sed/manual/html_node/Common-Commands.html#Common-Commands">GNU sed description</a></td>
</tr>
<tr>
<td><code>P</code></td><td>Compliant with <a href="https://www.gnu.org/software/sed/manual/html_node/Other-Commands.html#Other-Commands">GNU sed description</a></td>
</tr>
<tr>
<td><code>q</code></td><td>Compliant with <a href="https://www.gnu.org/software/sed/manual/html_node/Common-Commands.html#Common-Commands">GNU sed description</a>
</td><td>(except exit code extension)</td>
</tr>
<tr>
<td><code>r filename</code></td><td>Compliant with <a href="https://www.gnu.org/software/sed/manual/html_node/Other-Commands.html#Other-Commands">GNU sed description</a>
</td><td>(including double address extension but not reading from stdin)</td>
</tr>
<tr>
<td><code>s</code></td><td>Compliant with <a href="https://www.gnu.org/software/sed/manual/html_node/The-_0022s_0022-Command.html#The-_0022s_0022-Command">GNU sed description</a>
</td><td>(except escape sequences in replacement (\L, \l, \U, \u, \E),
modifiers e and M/m, and combination of modifier g and number)</td>
</tr>
<tr>
<td><code>t label</code></td><td>Compliant with <a href="https://www.gnu.org/software/sed/manual/html_node/Programming-Commands.html#Programming-Commands">GNU sed description</a></td>
</tr>
<tr>
<td><code>w filename</code></td><td>Compliant with <a href="https://www.gnu.org/software/sed/manual/html_node/Other-Commands.html#Other-Commands">GNU sed description</a>
</td><td>(including double address extension but not writing to stdout or stderr)</td>
</tr>
<tr>
<td><code>x</code></td><td>Compliant with <a href="https://www.gnu.org/software/sed/manual/html_node/Other-Commands.html#Other-Commands">GNU sed description</a></td>
</tr>
<tr>
<td><code>y</code></td><td>Compliant with <a href="https://www.gnu.org/software/sed/manual/html_node/Other-Commands.html#Other-Commands">GNU sed description</a></td>
</tr>
<tr>
<td><code>#</code></td><td>Compliant with <a href="https://www.gnu.org/software/sed/manual/html_node/Common-Commands.html#Other-Commands">GNU sed description</a>.
</td><td>(comments start anywhere in the line.)</td>
</tr>
</table>
<p>
The other commands specific to GNU sed are not implemented.
</p>
<hr id="Testing" />
<h3>Testing</h3>
<hr size="1" color="#C0C0C0" />
<p style="font-size:1px"> </p>
<h4>Description</h4>
<p>
The working of <code class=blue>sed.py</code> is tested and compared to
the behavior of GNU sed with a set of tests and a testing utility.
</p>
<p>
The tests are either coded in text files with .suite extension or may be
stored in test directories as standard sed scripts.
</p>
<p>
The test suites are:
</p>
<table>
<tr>
<td width=150><code>unit.suite</code></td><td>a text file
containing unitary tests</td>
</tr>
<tr>
<td><code>chang.suite</code></td><td>a text file containing
scripts from <a href="http://www.rtfiber.com.tw/~changyj/sed/">Roger
Chang web site</a></td>
</tr>
<tr>
<td><code>test-suite1</code></td><td>a set of scripts from <a
href="ftp://ftp.gnu.org/gnu/sed/">GNU sed test suite</a></td>
</tr>
<tr>
<td><code>test-suite2</code></td><td>a set of scripts from the <a
href="http://sed.sourceforge.net/grabbag/">seder's grab-bag</a>, <a
href="http://rosettacode.org/wiki/Rosetta_Code">Rosetta code web
site</a> and GitHub (<a
href="http://github.com/shinh/sedlisp">lisp</a>!)</td>
</tr>
<tr>
<td><code>test-suite3</code></td><td>additional unitary tests better
stored in a folder with some extra data text files</td>
</tr>
<tr>
<td><code>test-suite4</code></td><td>a set of scripts from the <a
href="http://http://sed.sourceforge.net/">sed $HOME</a></td>
</tr>
</table>
<p>
Note that the goal of these tests is not to check the correctness of the
scripts but to verify that <code class=blue>sed.py</code> and GNU sed
have the same behavior.
</p>
<p style="font-size:1px"> </p>
<hr size="1" color="#C0C0C0" />
<h4>Testing utility</h4>
<p>
Tests are launched and checked with the <code
class=blue>test-suite.py</code> Python script. This script uses either
<code class=blue>sed.py</code> to run the sed scripts, or any sed
executable. This enables to compare the working of <code
class=blue>sed.py</code> with the one of GNU sed.
</p>
<p>
The calling syntax is:
</p>
<pre>
test-suite.py <testsuite> [number] [-b executable] [-x list of script references]</pre>
<table>
<tr>
<td width=150><code class=blue>testsuite</code></td><td>either a
text file with .suite extension or a test directory</td>
</tr>
<tr>
<td><code class=blue>number</code></td><td>an optional reference
number of a test, when present only this tests is run</td>
</tr>
<tr>
<td><code class=blue>executable</code></td><td>an optional name or
path of a sed executable to use for testing</td>
</tr>
<tr>
<td><code class=blue>list of script references</code></td><td>an
optional list of tests to exclude for instance when a feature is not
implemented. A script reference is either the title of the test for
tests stored in modules, or the the name of the script file.</td>
</tr>
</table>
<p style="font-size:1px"> </p>
<hr size="1" color="#C0C0C0" />
<h4>Text file test suites</h4>
<p>
When tests are stored in a text file (with .suite extension), they are
made of four elements:
</p>
<ul>
<li>the title of the test</li>
<li>the script itself</li>
<li>the input list of lines</li>
<li>the expected result</li>
</ul>
<p>
The four elements of a test are separated with lines made of three
identical characters, for instance:
</p>
<pre>
---
Test substitution with global flag
---
s/an/AN/g
---
In Xanadu did Kubhla Khan
---
In XANadu did Kubhla KhAN
---</pre>
<p>
Note also that:
</p>
<ul>
<li>the script section may be empty, enabling to test a script on
various data without repeating the script.</li>
<li>The input and output sections may be empty, enabling to test various
scripts on the same data, without repeating the data.</li>
<li>Flags are set with a comment on the first line. As usual, #n
stops autoprint mode and extended regexp mode is set with
#r or #nr.</li>
<li>The expected result may be ??? when the test has no result and ends
with an error.</li>
<li>All text outside the test, i.e. before first delimiter or after last
delimiter, is ignored and acts like a comment.</li>
</ul>
<p style="font-size:1px"> </p>
<hr size="1" color="#C0C0C0" />
<h4>Directory test suites</h4>
<p>
When tests are stored in a directory, they are represented by three or
four files with same name but different extensions:
</p>
<ul>
<li>the script itself, with '.sed' extension</li>
<li>the input of the script, with '.inp' extension</li>
<li>the expected result of the script, with '.good' extension</li>
<li>possibly a file, with '.flags' extension, containing the sed switches -n and/or -r.</li>
</ul>
<p>
Some other files may be used when using reading or writing commands in
scripts. In that case, the expected written files must be named with
extension '.wgoodN' where N is the number of the expected written file.
</p>
<hr id="Timing" />
<h3>Timing</h3>
<hr size="1" color="#C0C0C0" />
<p style="font-size:1px"> </p>
<p>
A python implementation of sed has to face legitimate questions about
timing. Fortunately, results are not bad. Unfortunately, they
seem correlated with version number. Timings are given in seconds.
</p>
<table class="framed">
<tr>
<td class="framed">Platform</td>
<td class="framed">GNU sed 4.2.1</td>
<td class="framed">sed.py python 2.6</td>
<td class="framed">sed.py python 2.7</td>
<td class="framed">sed.py python 3.4</td>
</tr>
<tr>
<td class="framed">Windows7, Intel Xeon 3.2 GHz, 6 Gb RAM</td>
<td class="framed">19.4</td>
<td class="framed">19.1</td>
<td class="framed">22.6</td>
<td class="framed">26.9</td>
</tr>
<tr>
<td class="framed">Windows XP, Intel Pentium4 3.2 GHz, 4 Gb RAM</td>
<td class="framed">47.5</td>
<td class="framed">50.7</td>
<td class="framed">56.5</td>
<td class="framed">71.2</td>
</tr>
<tr>
<td class="framed">Linux, Intel Pentium4 3.2 GHz, 4 Gb RAM</td>
<td class="framed">-</td>
<td class="framed">-</td>
<td class="framed">51.0</td>
<td class="framed">-</td>
</tr>
</table>
<p>
Test conditions:
</p>
<ul>
<li>Only script files are used (scripts from folders testsuiteN). This
is to avoid measuring the time to extract scripts, inputs and results
from .suite files.</li>
<li>The given values are averaged from three consecutive test runs.</li>
</ul>
<p style="font-size:1px"> </p>
<hr id="Todo" />
<h3>To do list</h3>
<hr size="1" color="#C0C0C0" />
<p style="font-size:1px"> </p>
<p>
At one moment, one has to decide what will be in the release to come,
and what can be delayed. Here are some features which would be nice to
have but can be delayed to a future version.
</p>
<ul>
<li>Better POSIX compliance:</li>
<ul>
<li>multiple scripts on the command line (-e, -f)</li>
<li>multiple input file</li>
<li>character classes</li>
</ul>
<li>Better error handling (display of the number of the line in error)</li>
<li>Better error handling when testing (the error message could be tested)</li>
<li>Use sed.py as a basis for a sed debugger.</li>
<li>...</li>
</ul>
<hr />
<!-- Piwik -->
<script type="text/javascript">
var pkBaseURL = (("https:" == document.location.protocol) ? "https://www.godrago.net/piwik/" : "http://www.godrago.net/piwik/");
document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
</script><script type="text/javascript">
try {
var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 1);
piwikTracker.trackPageView();
piwikTracker.enableLinkTracking();
} catch( err ) {}
</script><noscript><p><img src="http://www.godrago.net/piwik/piwik.php?idsite=1" style="border:0" alt=""/></p></noscript>
<!-- End Piwik Tag -->
</body>
</html>