File: s2p.html

package info (click to toggle)
perl-doc-html 5.18.2-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 38,816 kB
  • ctags: 26,804
  • sloc: xml: 36; makefile: 10
file content (938 lines) | stat: -rw-r--r-- 42,620 bytes parent folder | download
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <title>s2p - perldoc.perl.org</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta http-equiv="Content-Language" content="en-gb">
  <link rel="search" type="application/opensearchdescription+xml" title="Search perldoc.perl.org" href="/static/search.xml"/>
  <link href="static/css-20100830.css" rel="stylesheet" rev="stylesheet" type="text/css" media="screen">
  <link href="static/exploreperl.css" rel="stylesheet" rev="stylesheet" type="text/css">
</head>

<body onLoad="perldoc.startup();" onPageShow="if (event.persisted) perldoc.startup();">
    <div id="page">
      
      <div id="header">
	<div id="homepage_link">
	  <a href="index.html"></a>
	</div>
	<div id="strapline">
	  Perl Programming Documentation
	</div>
	<div id="download_link" class="download">
	  <a href="http://www.perl.org/get.html">Download Perl</a>
	</div>
	<div id="explore_link" class="download">
	  <a id="explore_anchor" href="#">Explore</a>
	</div>
      </div>
      
      <div id="body">
        <div id="left_column">
          <div class="side_group">
            
	    <div class="side_panel doc_panel">
              <p>Manual</p>
              <ul>
                <li><a href="index-overview.html">Overview</a>
                <li><a href="index-tutorials.html">Tutorials</a>
                <li><a href="index-faq.html">FAQs</a>
                <li><a href="index-history.html">History / Changes</a>
                <li><a href="index-licence.html">License</a>
              </ul>
            </div>
            <div class="side_panel doc_panel">
              <p>Reference</p>
              <ul>
                <li><a href="index-language.html">Language</a>
                <li><a href="index-functions.html">Functions</a>
                <li><a href="perlop.html">Operators</a>
                <li><a href="perlvar.html">Special Variables</a>
                <li><a href="index-pragmas.html">Pragmas</a>
                <li><a href="index-utilities.html">Utilities</a>
                <li><a href="index-internals.html">Internals</a>
                <li><a href="index-platforms.html">Platform Specific</a>
              </ul>
            </div>
            <div class="side_panel doc_panel">
              <p>Modules</p>
              <ul>
		<li>
		
                
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		
                  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		
                  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		    
		  
		
                  
		
                  
		
                  
		    
		  
		
                  
		
                  
		
		
                    <a href="index-modules-A.html">A</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-B.html">B</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-C.html">C</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-D.html">D</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-E.html">E</a>
                    
                      
                        <li>
                      
                    
                
                    <a href="index-modules-F.html">F</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-G.html">G</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-H.html">H</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-I.html">I</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-L.html">L</a>
                    
                      
                        <li>
                      
                    
                
                    <a href="index-modules-M.html">M</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-N.html">N</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-O.html">O</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-P.html">P</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-S.html">S</a>
                    
                      
                        <li>
                      
                    
                
                    <a href="index-modules-T.html">T</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-U.html">U</a>
                    
                      
                        &bull;
                      
                    
                
                    <a href="index-modules-X.html">X</a>
                    
                
              </ul>
            </div>
            
	      <div class="side_panel doc_panel">
		<p>Tools</p>
		<ul>
		  <li><a href="preferences.html">Preferences</a>
		</ul>
	      </div>
            
          </div>
        </div>
        <div id="centre_column">
          <div id="content_header">
            <div id="title_bar">
              <div id="page_name">
                <h1>s2p</h1>
              </div>
              <div id="perl_version">
                Perl 5 version 18.2 documentation
              </div>
              <div class="page_links" id="page_links_top">
                <a href="#" onClick="toolbar.goToTop();return false;">Go to top</a>
		
              </div>
	      <div class="page_links" id="page_links_bottom">
		
                  <a href="#" id="page_index_toggle">Show page index</a> &bull;
		
                <a href="#" id="recent_pages_toggle">Show recent pages</a>		
	      </div>
	      <div id="search_form">
		<form action="search.html" method="GET" id="search">
		  <input type="text" name="q" id="search_box" alt="Search">
		</form>
	      </div>
            </div>
            <div id="breadcrumbs">
                
    <a href="index.html">Home</a> &gt;
    
      
        <a href="index-utilities.html">Utilities</a> &gt;
      
    
    s2p
  

            </div>
          </div>
          <div id="content_body">
	    <!--[if lt IE 7]>
 <div class="noscript">
   <p>
     <strong>It looks like you're using Internet Explorer 6. This is a very old
     browser which does not offer full support for modern websites.</strong>
   </p>
   <p>
     Unfortunately this means that this website will not work on
     your computer.
   </p>
   <p>
     Don't miss out though! To view the site (and get a better experience from
     many other websites), simply upgrade to
     <a href="http://www.microsoft.com/windows/Internet-explorer/default.aspx">Internet
Explorer 8</a>
     or download an alternative browser such as
     <a href="http://www.mozilla.com/en-US/firefox/firefox.html">Firefox</a>,
     <a href="http://www.apple.com/safari/download/">Safari</a>, or
     <a href="http://www.google.co.uk/chrome">Google Chrome</a>.
   </p>
   <p>
     All of these browsers are free. If you're using a PC at work, you may
     need to contact your IT administrator.
   </p>
 </div>
<![endif]-->
	    <noscript>
	      <div class="noscript">
	      <p>
                <strong>Please note: Many features of this site require JavaScript. You appear to have JavaScript disabled,
	        or are running a non-JavaScript capable web browser.</strong>
	      </p>
	      <p>
		To get the best experience, please enable JavaScript or download a modern web browser such as <a href="http://www.microsoft.com/windows/Internet-explorer/default.aspx">Internet Explorer 8</a>, <a href="http://www.mozilla.com/en-US/firefox/firefox.html">Firefox</a>, <a href="http://www.apple.com/safari/download/">Safari</a>, or <a href="http://www.google.co.uk/chrome">Google Chrome</a>.
              </p>
	      </div>
	    </noscript>

	    <div id="recent_pages" class="hud_container">
	      <div id="recent_pages_header" class="hud_header">
		<div id="recent_pages_close" class="hud_close"><a href="#" onClick="recentPages.hide();return false;"></a></div>
		<div id="recent_pages_title" class="hud_title"><span class="hud_span_top">Recently read</span></div>
		<div id="recent_pages_topright" class="hud_topright"></div>
	      </div>
	      <div id="recent_pages_content" class="hud_content">
	      </div>
	      <div id="recent_pages_footer" class="hud_footer">
		<div id="recent_pages_bottomleft" class="hud_bottomleft"></div>
		<div id="recent_pages_bottom" class="hud_bottom"><span class="hud_span_bottom"></span></div>
		<div id="recent_pages_resize" class="hud_resize"></div>
	      </div>
	    </div>
  
	    <div id="from_search"></div>
            <h1>s2p</h1>


  <!--    -->
<ul><li><a href="#NAME">NAME</a><li><a href="#SYNOPSIS">SYNOPSIS</a><li><a href="#DESCRIPTION">DESCRIPTION</a><li><a href="#OPTIONS">OPTIONS</a><li><a href="#COMMANDS">COMMANDS</a><ul><li><a href="#Addresses">Addresses</a><li><a href="#Functions">Functions</a></ul><li><a href="#BASIC-REGULAR-EXPRESSIONS">BASIC REGULAR EXPRESSIONS</a><ul><li><a href="#Atoms">Atoms</a><li><a href="#Bounds">Bounds</a><li><a href="#Bracket-Expressions">Bracket Expressions</a><li><a href="#Additional-Atoms">Additional Atoms</a></ul><li><a href="#ENVIRONMENT">ENVIRONMENT</a><li><a href="#DIAGNOSTICS">DIAGNOSTICS</a><li><a href="#EXAMPLE">EXAMPLE</a><li><a href="#SED-SCRIPT-TRANSLATION">SED SCRIPT TRANSLATION</a><li><a href="#SEE-ALSO">SEE ALSO</a><li><a href="#BUGS">BUGS</a><li><a href="#STANDARDS">STANDARDS</a><li><a href="#AUTHOR">AUTHOR</a><li><a href="#COPYRIGHT-and-LICENSE">COPYRIGHT and LICENSE</a></ul><a name="NAME"></a><h1>NAME</h1>
<p>psed - a stream editor</p>
<a name="SYNOPSIS"></a><h1>SYNOPSIS</h1>
<pre class="verbatim"><ol><li>   <span class="w">psed</span> <span class="s">[</span>-<span class="w">an</span><span class="s">]</span> <span class="w">script</span> <span class="s">[</span><span class="w">file</span> ...<span class="s">]</span></li><li>   <span class="w">psed</span> <span class="s">[</span>-<span class="w">an</span><span class="s">]</span> <span class="s">[</span>-e <span class="w">script</span><span class="s">]</span> <span class="s">[</span>-f <span class="w">script</span>-<span class="w">file</span><span class="s">]</span> <span class="s">[</span><span class="w">file</span> ...<span class="s">]</span></li><li></li><li>   <span class="w">s2p</span>  <span class="s">[</span>-<span class="w">an</span><span class="s">]</span> <span class="s">[</span>-e <span class="w">script</span><span class="s">]</span> <span class="s">[</span>-f <span class="w">script</span>-<span class="w">file</span><span class="s">]</span></li></ol></pre><a name="DESCRIPTION"></a><h1>DESCRIPTION</h1>
<p>A stream editor reads the input stream consisting of the specified files
(or standard input, if none are given), processes is line by line by
applying a script consisting of edit commands, and writes resulting lines
to standard output. The filename '<code class="inline">-</code>
' may be used to read standard input.</p>
<p>The edit script is composed from arguments of <b>-e</b> options and
script-files, in the given order. A single script argument may be specified
as the first parameter.</p>
<p>If this program is invoked with the name <i>s2p</i>, it will act as a
sed-to-Perl translator. See <a href="#SED-SCRIPT-TRANSLATION">SED SCRIPT TRANSLATION</a>.</p>
<p><b>sed</b> returns an exit code of 0 on success or &gt;0 if an error occurred.</p>
<a name="OPTIONS"></a><h1>OPTIONS</h1>
<ul>
<li><a name="*-a*"></a><b><b>-a</b></b>
<p>A file specified as argument to the <b>w</b> edit command is by default
opened before input processing starts. Using <b>-a</b>, opening of such
files is delayed until the first line is actually written to the file.</p>
</li>
<li><a name="*-e*-_script_"></a><b><b>-e</b> <i>script</i></b>
<p>The editing commands defined by <i>script</i> are appended to the script.
Multiple commands must be separated by newlines.</p>
</li>
<li><a name="*-f*-_script-file_"></a><b><b>-f</b> <i>script-file</i></b>
<p>Editing commands from the specified <i>script-file</i> are read and appended
to the script.</p>
</li>
<li><a name="*-n*"></a><b><b>-n</b></b>
<p>By default, a line is written to standard output after the editing script
has been applied to it. The <b>-n</b> option suppresses automatic printing.</p>
</li>
</ul>
<a name="COMMANDS"></a><h1>COMMANDS</h1>
<p><b>sed</b> command syntax is defined as</p>
<p>   [<i>address</i>[<b>,</b><i>address</i>]][<b>!</b>]<i>function</i>[<i>argument</i>]</p>
<p>with whitespace being permitted before or after addresses, and between
the function character and the argument. The <i>address</i>es and the
address inverter (<code class="inline">!</code>
) are used to restrict the application of a
command to the selected line(s) of input.</p>
<p>Each command must be on a line of its own, except where noted in
the synopses below.</p>
<p>The edit cycle performed on each input line consist of reading the line
(without its trailing newline character) into the <i>pattern space</i>,
applying the applicable commands of the edit script, writing the final
contents of the pattern space and a newline to the standard output.
A <i>hold space</i> is provided for saving the contents of the
pattern space for later use.</p>
<a name="Addresses"></a><h2>Addresses</h2>
<p>A sed address is either a line number or a pattern, which may be combined
arbitrarily to construct ranges. Lines are numbered across all input files.</p>
<p>Any address may be followed by an exclamation mark ('<code class="inline">!</code>
'), selecting
all lines not matching that address.</p>
<ul>
<li><a name="_number_"></a><b><i>number</i></b>
<p>The line with the given number is selected.</p>
</li>
<li><a name="*%24*"></a><b><b>$</b></b>
<p>A dollar sign (<code class="inline"><span class="i">$</span></code>
) is the line number of the last line of the input stream.</p>
</li>
<li><a name="*%2f*_regular-expression_*%2f*"></a><b><b>/</b><i>regular expression</i><b>/</b></b>
<p>A pattern address is a basic regular expression (see 
<a href="#BASIC-REGULAR-EXPRESSIONS">BASIC REGULAR EXPRESSIONS</a>), between the delimiting character <code class="inline">/</code>.
Any other character except <code class="inline">\</code>
 or newline may be used to delimit a
pattern address when the initial delimiter is prefixed with a
backslash ('<code class="inline">\</code>
').</p>
</li>
</ul>
<p>If no address is given, the command selects every line.</p>
<p>If one address is given, it selects the line (or lines) matching the
address.</p>
<p>Two addresses select a range that begins whenever the first address
matches, and ends (including that line) when the second address matches.
If the first (second) address is a matching pattern, the second 
address is not applied to the very same line to determine the end of
the range. Likewise, if the second address is a matching pattern, the
first address is not applied to the very same line to determine the
begin of another range. If both addresses are line numbers,
and the second line number is less than the first line number, then
only the first line is selected.</p>
<a name="Functions"></a><h2>Functions</h2>
<p>The maximum permitted number of addresses is indicated with each
function synopsis below.</p>
<p>The argument <i>text</i> consists of one or more lines following the command.
Embedded newlines in <i>text</i> must be preceded with a backslash.  Other
backslashes in <i>text</i> are deleted and the following character is taken
literally.</p>
<ul>
<li><a name="%5b1addr%5d*a%5c*-_text_"></a><b>[1addr]<b>a\</b> <i>text</i></b>
<p>Write <i>text</i> (which must start on the line following the command)
to standard output immediately before reading the next line
of input, either by executing the <b>N</b> function or by beginning a new cycle.</p>
</li>
<li><a name="%5b2addr%5d*b*-%5b_label_%5d"></a><b>[2addr]<b>b</b> [<i>label</i>]</b>
<p>Branch to the <b>:</b> function with the specified <i>label</i>. If no label
is given, branch to the end of the script.</p>
</li>
<li><a name="%5b2addr%5d*c%5c*-_text_"></a><b>[2addr]<b>c\</b> <i>text</i></b>
<p>The line, or range of lines, selected by the address is deleted. 
The <i>text</i> (which must start on the line following the command)
is written to standard output. With an address range, this occurs at
the end of the range.</p>
</li>
<li><a name="%5b2addr%5d*d*"></a><b>[2addr]<b>d</b></b>
<p>Deletes the pattern space and starts the next cycle.</p>
</li>
<li><a name="%5b2addr%5d*D*"></a><b>[2addr]<b>D</b></b>
<p>Deletes the pattern space through the first embedded newline or to the end.
If the pattern space becomes empty, a new cycle is started, otherwise
execution of the script is restarted.</p>
</li>
<li><a name="%5b2addr%5d*g*"></a><b>[2addr]<b>g</b></b>
<p>Replace the contents of the pattern space with the hold space.</p>
</li>
<li><a name="%5b2addr%5d*G*"></a><b>[2addr]<b>G</b></b>
<p>Append a newline and the contents of the hold space to the pattern space.</p>
</li>
<li><a name="%5b2addr%5d*h*"></a><b>[2addr]<b>h</b></b>
<p>Replace the contents of the hold space with the pattern space.</p>
</li>
<li><a name="%5b2addr%5d*H*"></a><b>[2addr]<b>H</b></b>
<p>Append a newline and the contents of the pattern space to the hold space.</p>
</li>
<li><a name="%5b1addr%5d*i%5c*-_text_"></a><b>[1addr]<b>i\</b> <i>text</i></b>
<p>Write the <i>text</i> (which must start on the line following the command)
to standard output.</p>
</li>
<li><a name="%5b2addr%5d*l*"></a><b>[2addr]<b>l</b></b>
<p>Print the contents of the pattern space: non-printable characters are
shown in C-style escaped form; long lines are split and have a trailing
^'<code class="inline">\</code>
' at the point of the split; the true end of a line is marked with
a '<code class="inline"><span class="i">$</span></code>
'. Escapes are: '\a', '\t', '\n', '\f', '\r', '\e' for
BEL, HT, LF, FF, CR, ESC, respectively, and '\' followed by a three-digit
octal number for all other non-printable characters.</p>
</li>
<li><a name="%5b2addr%5d*n*"></a><b>[2addr]<b>n</b></b>
<p>If automatic printing is enabled, write the pattern space to the standard
output. Replace the pattern space with the next line of input. If
there is no more input, processing is terminated.</p>
</li>
<li><a name="%5b2addr%5d*N*"></a><b>[2addr]<b>N</b></b>
<p>Append a newline and the next line of input to the pattern space. If
there is no more input, processing is terminated.</p>
</li>
<li><a name="%5b2addr%5d*p*"></a><b>[2addr]<b>p</b></b>
<p>Print the pattern space to the standard output. (Use the <b>-n</b> option
to suppress automatic printing at the end of a cycle if you want to
avoid double printing of lines.)</p>
</li>
<li><a name="%5b2addr%5d*P*"></a><b>[2addr]<b>P</b></b>
<p>Prints the pattern space through the first embedded newline or to the end.</p>
</li>
<li><a name="%5b1addr%5d*q*"></a><b>[1addr]<b>q</b></b>
<p>Branch to the end of the script and quit without starting a new cycle.</p>
</li>
<li><a name="%5b1addr%5d*r*-_file_"></a><b>[1addr]<b>r</b> <i>file</i></b>
<p>Copy the contents of the <i>file</i> to standard output immediately before
the next attempt to read a line of input. Any error encountered while
reading <i>file</i> is silently ignored.</p>
</li>
<li><a name="%5b2addr%5d*s%2f*_regular-expression_*%2f*_replacement_*%2f*_flags_"></a><b>[2addr]<b>s/</b><i>regular expression</i><b>/</b><i>replacement</i><b>/</b><i>flags</i></b>
<p>Substitute the <i>replacement</i> string for the first substring in
the pattern space that matches the <i>regular expression</i>.
Any character other than backslash or newline can be used instead of a 
slash to delimit the regular expression and the replacement.
To use the delimiter as a literal character within the regular expression
and the replacement, precede the character by a backslash ('<code class="inline">\</code>
').</p>
<p>Literal newlines may be embedded in the replacement string by
preceding a newline with a backslash.</p>
<p>Within the replacement, an ampersand ('<code class="inline"><span class="i">&amp;</span></code>
') is replaced by the string
matching the regular expression. The strings '<code class="inline">\<span class="n">1</span></code>
' through '<code class="inline">\<span class="n">9</span></code>
' are
replaced by the corresponding subpattern (see <a href="#BASIC-REGULAR-EXPRESSIONS">BASIC REGULAR EXPRESSIONS</a>).
To get a literal '<code class="inline"><span class="i">&amp;</span></code>
' or '<code class="inline">\</code>
' in the replacement text, precede it
by a backslash.</p>
<p>The following <i>flags</i> modify the behaviour of the <b>s</b> command:</p>
<ul>
<li><a name="*g*"></a><b><b>g</b></b>
<p>The replacement is performed for all matching, non-overlapping substrings
of the pattern space.</p>
</li>
<li><a name="*1*..*9*"></a><b><b>1</b>..<b>9</b></b>
<p>Replace only the n-th matching substring of the pattern space.</p>
</li>
<li><a name="*p*"></a><b><b>p</b></b>
<p>If the substitution was made, print the new value of the pattern space.</p>
</li>
<li><a name="*w*-_file_"></a><b><b>w</b> <i>file</i></b>
<p>If the substitution was made, write the new value of the pattern space
to the specified file.</p>
</li>
</ul>
</li>
<li><a name="%5b2addr%5d*t*-%5b_label_%5d"></a><b>[2addr]<b>t</b> [<i>label</i>]</b>
<p>Branch to the <b>:</b> function with the specified <i>label</i> if any <b>s</b>
substitutions have been made since the most recent reading of an input line
or execution of a <b>t</b> function. If no label is given, branch to the end of
the script.</p>
</li>
<li><a name="%5b2addr%5d*w*-_file_"></a><b>[2addr]<b>w</b> <i>file</i></b>
<p>The contents of the pattern space are written to the <i>file</i>.</p>
</li>
<li><a name="%5b2addr%5d*x*"></a><b>[2addr]<b>x</b></b>
<p>Swap the contents of the pattern space and the hold space.</p>
</li>
<li><a name="%5b2addr%5d*y**%2f*_string1_*%2f*_string2_*%2f*"></a><b>[2addr]<b>y</b><b>/</b><i>string1</i><b>/</b><i>string2</i><b>/</b></b>
<p>In the pattern space, replace all characters occurring in <i>string1</i> by the
character at the corresponding position in <i>string2</i>. It is possible
to use any character (other than a backslash or newline) instead of a
slash to delimit the strings.  Within <i>string1</i> and <i>string2</i>, a
backslash followed by any character other than a newline is that literal
character, and a backslash followed by an 'n' is replaced by a newline
character.</p>
</li>
<li><a name="%5b1addr%5d*%3d*"></a><b>[1addr]<b>=</b></b>
<p>Prints the current line number on the standard output.</p>
</li>
<li><a name="%5b0addr%5d*%3a*-%5b_label_%5d"></a><b>[0addr]<b>:</b> [<i>label</i>]</b>
<p>The command specifies the position of the <i>label</i>. It has no other effect.</p>
</li>
<li><a name="%5b2addr%5d*%7b*-%5b_command_%5d"></a><b>[2addr]<b>{</b> [<i>command</i>]</b>
</li>
<li><a name="%5b0addr%5d*%7d*"></a><b>[0addr]<b>}</b></b>
<p>These two commands begin and end a command list. The first command may
be given on the same line as the opening <b>{</b> command. The commands
within the list are jointly selected by the address(es) given on the
<b>{</b> command (but may still have individual addresses).</p>
</li>
<li><a name="%5b0addr%5d*%23*-%5b_comment_%5d"></a><b>[0addr]<b>#</b> [<i>comment</i>]</b>
<p>The entire line is ignored (treated as a comment). If, however, the first
two characters in the script are '<code class="inline"><span class="c">#n</span></code>
', automatic printing of output is
suppressed, as if the <b>-n</b> option were given on the command line.</p>
</li>
</ul>
<a name="BASIC-REGULAR-EXPRESSIONS"></a><h1>BASIC REGULAR EXPRESSIONS</h1>
<p>A <i>Basic Regular Expression</i> (BRE), as defined in POSIX 1003.2, consists
of <i>atoms</i>, for matching parts of a string, and <i>bounds</i>, specifying
repetitions of a preceding atom.</p>
<a name="Atoms"></a><h2>Atoms</h2>
<p>The possible atoms of a BRE are: <b>.</b>, matching any single character;
<b>^</b> and <b>$</b>, matching the null string at the beginning or end
of a string, respectively; a <i>bracket expressions</i>, enclosed
in <b>[</b> and <b>]</b> (see below); and any single character with no
other significance (matching that character). A <b>\</b> before one
of: <b>.</b>, <b>^</b>, <b>$</b>, <b>[</b>, <b>*</b>, <b>\</b>, matching the character
after the backslash. A sequence of atoms enclosed in <b>\(</b> and <b>\)</b>
becomes an atom and establishes the target for a <i>backreference</i>,
consisting of the substring that actually matches the enclosed atoms.
Finally, <b>\</b> followed by one of the digits <b>0</b> through <b>9</b> is a
backreference.</p>
<p>A <b>^</b> that is not first, or a <b>$</b> that is not last does not have
a special significance and need not be preceded by a backslash to
become literal. The same is true for a <b>]</b>, that does not terminate
a bracket expression.</p>
<p>An unescaped backslash cannot be last in a BRE.</p>
<a name="Bounds"></a><h2>Bounds</h2>
<p>The BRE bounds are: <b>*</b>, specifying 0 or more matches of the preceding
atom; <b>\{</b><i>count</i><b>\}</b>, specifying that many repetitions;
<b>\{</b><i>minimum</i><b>,\}</b>, giving a lower limit; and
<b>\{</b><i>minimum</i><b>,</b><i>maximum</i><b>\}</b> finally defines a lower and upper
bound.</p>
<p>A bound appearing as the first item in a BRE is taken literally.</p>
<a name="Bracket-Expressions"></a><h2>Bracket Expressions</h2>
<p>A <i>bracket expression</i> is a list of characters, character ranges
and character classes enclosed in <b>[</b> and <b>]</b> and matches any
single character from the represented set of characters.</p>
<p>A character range is written as two characters separated by <b>-</b> and
represents all characters (according to the character collating sequence)
that are not less than the first and not greater than the second.
(Ranges are very collating-sequence-dependent, and portable programs
should avoid relying on them.)</p>
<p>A character class is one of the class names</p>
<pre class="verbatim"><ol><li>   <span class="w">alnum</span>     <span class="w">digit</span>     <span class="w">punct</span></li><li>   <span class="w">alpha</span>     <span class="w">graph</span>     <span class="w">space</span></li><li>   <span class="w">blank</span>     <span class="w">lower</span>     <span class="w">upper</span></li><li>   <span class="w">cntrl</span>     <a class="l_k" href="functions/print.html">print</a>     <span class="i">xdigit</span></li></ol></pre><p>enclosed in <b>[:</b> and <b>:]</b> and represents the set of characters
as defined in ctype(3).</p>
<p>If the first character after <b>[</b> is <b>^</b>, the sense of matching is
inverted.</p>
<p>To include a literal '<code class="inline">^</code>', place it anywhere else but first. To
include a literal '<code class="inline">]</code>' place it first or immediately after an
initial <b>^</b>. To include a literal '<code class="inline">-</code>
' make it the first (or
second after <b>^</b>) or last character, or the second endpoint of
a range.</p>
<p>The special bracket expression constructs <code class="inline">[[:&lt;:]]</code> and <code class="inline">[[:&gt;:]]</code> 
match the null string at the beginning and end of a word respectively.
(Note that neither is identical to Perl's '\b' atom.)</p>
<a name="Additional-Atoms"></a><h2>Additional Atoms</h2>
<p>Since some sed implementations provide additional regular expression
atoms (not defined in POSIX 1003.2), <b>psed</b> is capable of translating
the following backslash escapes:</p>
<ul>
<li><a name="*%5c%3c*-This-is-the-same-as-%5b%5b%3a%3e%3a%5d%5d."></a><b><b>\&lt;</b> This is the same as <code class="inline">[[:&gt;:]]</code>.</b>
</li>
<li><a name="*%5c%3e*-This-is-the-same-as-%5b%5b%3a%3c%3a%5d%5d."></a><b><b>\&gt;</b> This is the same as <code class="inline">[[:&lt;:]]</code>.</b>
</li>
<li><a name="*%5cw*-This-is-an-abbreviation-for-%5b%5b%3aalnum%3a%5d_%5d."></a><b><b>\w</b> This is an abbreviation for <code class="inline">[[:alnum:]_]</code>.</b>
</li>
<li><a name="*%5cW*-This-is-an-abbreviation-for-%5b%5e%5b%3aalnum%3a%5d_%5d."></a><b><b>\W</b> This is an abbreviation for <code class="inline">[^[:alnum:]_]</code>.</b>
</li>
<li><a name="*%5cy*-Match-the-empty-string-at-a-word-boundary."></a><b><b>\y</b> Match the empty string at a word boundary.</b>
</li>
<li><a name="*%5cB*-Match-the-empty-string-between-any-two-either-word-or-non-word-characters."></a><b><b>\B</b> Match the empty string between any two either word or non-word characters.</b>
</li>
</ul>
<p>To enable this feature, the environment variable PSEDEXTBRE must be set
to a string containing the requested characters, e.g.:
<code class="inline"><span class="w">PSEDEXTBRE</span>=<span class="q">&#39;&lt;&gt;wW&#39;</span></code>
.</p>
<a name="ENVIRONMENT"></a><h1>ENVIRONMENT</h1>
<p>The environment variable <code class="inline"><span class="w">PSEDEXTBRE</span></code>
 may be set to extend BREs.
See <a href="#Additional-Atoms">Additional Atoms</a>.</p>
<a name="DIAGNOSTICS"></a><h1>DIAGNOSTICS</h1>
<ul>
<li><a name="ambiguous-translation-for-character-'%25s'-in-'y'-command"></a><b>ambiguous translation for character '%s' in 'y' command</b>
<p>The indicated character appears twice, with different translations.</p>
</li>
<li><a name="'%5b'-cannot-be-last-in-pattern"></a><b>'[' cannot be last in pattern</b>
<p>A '[' in a BRE indicates the beginning of a <i>bracket expression</i>.</p>
</li>
<li><a name="'%5c'-cannot-be-last-in-pattern"></a><b>'\' cannot be last in pattern</b>
<p>A '\' in a BRE is used to make the subsequent character literal.</p>
</li>
<li><a name="'%5c'-cannot-be-last-in-substitution"></a><b>'\' cannot be last in substitution</b>
<p>A '\' in a substitution string is used to make the subsequent character literal.</p>
</li>
<li><a name="conflicting-flags-'%25s'"></a><b>conflicting flags '%s'</b>
<p>In an <b>s</b> command, either the 'g' flag and an n-th occurrence flag, or
multiple n-th occurrence flags are specified. Note that only the digits
^'1' through '9' are permitted.</p>
</li>
<li><a name="duplicate-label-%25s-(first-defined-at-%25s)"></a><b>duplicate label %s (first defined at %s)</b>
</li>
<li><a name="excess-address(es)"></a><b>excess address(es)</b>
<p>The command has more than the permitted number of addresses.</p>
</li>
<li><a name="extra-characters-after-command-(%25s)"></a><b>extra characters after command (%s)</b>
</li>
<li><a name="illegal-option-'%25s'"></a><b>illegal option '%s'</b>
</li>
<li><a name="improper-delimiter-in-s-command"></a><b>improper delimiter in s command</b>
<p>The BRE and substitution may not be delimited with '\' or newline.</p>
</li>
<li><a name="invalid-address-after-'%2c'"></a><b>invalid address after ','</b>
</li>
<li><a name="invalid-backreference-(%25s)"></a><b>invalid backreference (%s)</b>
<p>The specified backreference number exceeds the number of backreferences
in the BRE.</p>
</li>
<li><a name="invalid-repeat-clause-'%5c%7b%25s%5c%7d'"></a><b>invalid repeat clause '\{%s\}'</b>
<p>The repeat clause does not contain a valid integer value, or pair of
values.</p>
</li>
<li><a name="malformed-regex%2c-1st-address"></a><b>malformed regex, 1st address</b>
</li>
<li><a name="malformed-regex%2c-2nd-address"></a><b>malformed regex, 2nd address</b>
</li>
<li><a name="malformed-regular-expression"></a><b>malformed regular expression</b>
</li>
<li><a name="malformed-substitution-expression"></a><b>malformed substitution expression</b>
</li>
<li><a name="malformed-'y'-command-argument"></a><b>malformed 'y' command argument</b>
<p>The first or second string of a <b>y</b> command  is syntactically incorrect.</p>
</li>
<li><a name="maximum-less-than-minimum-in-'%5c%7b%25s%5c%7d'"></a><b>maximum less than minimum in '\{%s\}'</b>
</li>
<li><a name="no-script-command-given"></a><b>no script command given</b>
<p>There must be at least one <b>-e</b> or one <b>-f</b> option specifying a
script or script file.</p>
</li>
<li><a name="'%5c'-not-valid-as-delimiter-in-'y'-command"></a><b>'\' not valid as delimiter in 'y' command</b>
</li>
<li><a name="option--e-requires-an-argument"></a><b>option -e requires an argument</b>
</li>
<li><a name="option--f-requires-an-argument"></a><b>option -f requires an argument</b>
</li>
<li><a name="'s'-command-requires-argument"></a><b>'s' command requires argument</b>
</li>
<li><a name="start-of-unterminated-'%7b'"></a><b>start of unterminated '{'</b>
</li>
<li><a name="string-lengths-in-'y'-command-differ"></a><b>string lengths in 'y' command differ</b>
<p>The translation table strings in a <b>y</b> command must have equal lengths.</p>
</li>
<li><a name="undefined-label-'%25s'"></a><b>undefined label '%s'</b>
</li>
<li><a name="unexpected-'%7d'"></a><b>unexpected '}'</b>
<p>A <b>}</b> command without a preceding <b>{</b> command was encountered.</p>
</li>
<li><a name="unexpected-end-of-script"></a><b>unexpected end of script</b>
<p>The end of the script was reached although a text line after a
<b>a</b>, <b>c</b> or <b>i</b> command indicated another line.</p>
</li>
<li><a name="unknown-command-'%25s'"></a><b>unknown command '%s'</b>
</li>
<li><a name="unterminated-'%5b'"></a><b>unterminated '['</b>
<p>A BRE contains an unterminated bracket expression.</p>
</li>
<li><a name="unterminated-'%5c('"></a><b>unterminated '\('</b>
<p>A BRE contains an unterminated backreference.</p>
</li>
<li><a name="'%5c%7b'-without-closing-'%5c%7d'"></a><b>'\{' without closing '\}'</b>
<p>A BRE contains an unterminated bounds specification.</p>
</li>
<li><a name="'%5c)'-without-preceding-'%5c('"></a><b>'\)' without preceding '\('</b>
</li>
<li><a name="'y'-command-requires-argument"></a><b>'y' command requires argument</b>
</li>
</ul>
<a name="EXAMPLE"></a><h1>EXAMPLE</h1>
<p>The basic material for the preceding section was generated by running
the sed script</p>
<pre class="verbatim"><ol><li>   #no autoprint</li><li>   s/^.*Warn( *"\([^"]*\)".*$/\1/</li><li>   t process</li><li>   b</li><li>   :process</li><li>   s/$!/%s/g</li><li>   s/$[_[:alnum:]]\{1,\}/%s/g</li><li>   s/\\\\/\\/g</li><li>   s/^/=item /</li><li>   p</li></ol></pre><p>on the program's own text, and piping the output into <code class="inline"><a class="l_k" href="functions/sort.html">sort</a> -u</code>
.</p>
<a name="SED-SCRIPT-TRANSLATION"></a><h1>SED SCRIPT TRANSLATION</h1>
<p>If this program is invoked with the name <i>s2p</i> it will act as a
sed-to-Perl translator. After option processing (all other
arguments are ignored), a Perl program is printed on standard
output, which will process the input stream (as read from all
arguments) in the way defined by the sed script and the option setting
used for the translation.</p>
<a name="SEE-ALSO"></a><h1>SEE ALSO</h1>
<p>perl(1), re_format(7)</p>
<a name="BUGS"></a><h1>BUGS</h1>
<p>The <b>l</b> command will show escape characters (ESC) as '<code class="inline">\<span class="w">e</span></code>
', but
a vertical tab (VT) in octal.</p>
<p>Trailing spaces are truncated from labels in <b>:</b>, <b>t</b> and <b>b</b> commands.</p>
<p>The meaning of an empty regular expression ('<code class="inline"><span class="q">//</span></code>
'), as defined by <b>sed</b>,
is "the last pattern used, at run time". This deviates from the Perl
interpretation, which will re-use the "last last successfully executed
regular expression". Since keeping track of pattern usage would create
terribly cluttered code, and differences would only appear in obscure
context (where other <b>sed</b> implementations appear to deviate, too),
the Perl semantics was adopted. Note that common usage of this feature,
such as in <code class="inline"><span class="q">/abc/s</span>//<span class="w">xyz</span>/</code>
, will work as expected.</p>
<p>Collating elements (of bracket expressions in BREs) are not implemented.</p>
<a name="STANDARDS"></a><h1>STANDARDS</h1>
<p>This <b>sed</b> implementation conforms to the IEEE Std1003.2-1992 ("POSIX.2")
definition of <b>sed</b>, and is compatible with the <i>OpenBSD</i>
implementation, except where otherwise noted (see <a href="#BUGS">BUGS</a>).</p>
<a name="AUTHOR"></a><h1>AUTHOR</h1>
<p>This Perl implementation of <i>sed</i> was written by Wolfgang Laun,
<i>Wolfgang.Laun@alcatel.at</i>.</p>
<a name="COPYRIGHT-and-LICENSE"></a><h1>COPYRIGHT and LICENSE</h1>
<p>This program is free and open software. You may use, modify,
distribute, and sell this program (and any modified variants) in any
way you wish, provided you do not restrict others from doing the same.</p>




  <div id="page_index" class="hud_container">
    <div id="page_index_header" class="hud_header">
      <div id="page_index_close" class="hud_close"><a href="#" onClick="pageIndex.hide();return false;"></a></div>
      <div id="page_index_title" class="hud_title"><span class="hud_span_top">Page index</span></div>
      <div id="page_index_topright" class="hud_topright"></div>
    </div>
    <div id="page_index_content" class="hud_content">
      <ul><li><a href="#NAME">NAME</a><li><a href="#SYNOPSIS">SYNOPSIS</a><li><a href="#DESCRIPTION">DESCRIPTION</a><li><a href="#OPTIONS">OPTIONS</a><li><a href="#COMMANDS">COMMANDS</a><ul><li><a href="#Addresses">Addresses</a><li><a href="#Functions">Functions</a></ul><li><a href="#BASIC-REGULAR-EXPRESSIONS">BASIC REGULAR EXPRESSIONS</a><ul><li><a href="#Atoms">Atoms</a><li><a href="#Bounds">Bounds</a><li><a href="#Bracket-Expressions">Bracket Expressions</a><li><a href="#Additional-Atoms">Additional Atoms</a></ul><li><a href="#ENVIRONMENT">ENVIRONMENT</a><li><a href="#DIAGNOSTICS">DIAGNOSTICS</a><li><a href="#EXAMPLE">EXAMPLE</a><li><a href="#SED-SCRIPT-TRANSLATION">SED SCRIPT TRANSLATION</a><li><a href="#SEE-ALSO">SEE ALSO</a><li><a href="#BUGS">BUGS</a><li><a href="#STANDARDS">STANDARDS</a><li><a href="#AUTHOR">AUTHOR</a><li><a href="#COPYRIGHT-and-LICENSE">COPYRIGHT and LICENSE</a></ul>
    </div>
    <div id="page_index_footer" class="hud_footer">
      <div id="page_index_bottomleft" class="hud_bottomleft"></div>
      <div id="page_index_bottom" class="hud_bottom"><span class="hud_span_bottom"></span></div>
      <div id="page_index_resize" class="hud_resize"></div>
    </div>
  </div>


	    &nbsp;
          </div>
          <div id="content_footer">
          </div>
        </div>
        <div class="clear"></div>
      </div>
      
    <div id="footer">
      <div id="footer_content">
        <div id="footer_strapline">
          perldoc.perl.org - Official documentation for the Perl programming language
        </div>
        <div id="footer_links">
          <div id="address">
            <p class="name">Contact details</p>
            <p class="address">
	      Site maintained by <a href="mailto:jj@jonallen.info">Jon Allen (JJ)</a><br>
	    </p>
            <p class="contact">
              Documentation maintained by the <a href="http://lists.cpan.org/showlist.cgi?name=perl5-porters">Perl 5 Porters</a>
            </p>
          </div>
          <ul class="f1">
            <li>Manual
              <ul class="f2">
                <li><a href="index-overview.html">Overview</a>
                <li><a href="index-tutorials.html">Tutorials</a>
                <li><a href="index-faq.html">FAQs</a>
                <li><a href="index-history.html">Changes</a>
              </ul>
            <li>Reference
              <ul class="f2">
                <li><a href="index-language.html">Language</a>
                <li><a href="index-functions.html">Functions</a>
                <li><a href="perlop.html">Operators</a>
                <li><a href="perlvar.html">Variables</a>
              </ul>
            <li>Modules
              <ul class="f2">
                <li><a href="index-modules-A.html">Modules</a>
                <li><a href="index-pragmas.html">Pragmas</a>
                <li><a href="index-utilities.html">Utilities</a>
              </ul>
            <li>Misc
              <ul class="f2">
                <li><a href="index-licence.html">License</a>
                <li><a href="index-internals.html">Internals</a>
                <li><a href="index-platforms.html">Platforms</a>
              </ul>          </ul>
          <div class="clear"></div>
        </div>
      </div>
      <div id="footer_end">
      </div>
    </div>
      
    </div>
      <script language="JavaScript" type="text/javascript" src="static/exploreperl.js"></script>
      <script language="JavaScript" src="static/combined-20100403.js" type="text/javascript"></script>
<script language="JavaScript" type="text/javascript">
  perldoc.setPath(0);
  perldoc.pageName    = 's2p';
  perldoc.pageAddress = 's2p.html';
  perldoc.contentPage = 1;
  explorePerl.render();
  explorePerl.addEvents('explore_anchor');
</script>
    
  </body>
</html>