sed.1 (26826) | sed.1 (28066) |
---|---|
1.\" Copyright (c) 1992, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" This code is derived from software contributed to Berkeley by 5.\" the Institute of Electrical and Electronics Engineers, Inc. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions --- 38 unchanged lines hidden (view full) --- 47.Op Ar file ... 48.Nm sed 49.Op Fl an 50.Op Fl e Ar command 51.Op Fl f Ar command_file 52.Op Ar file ... 53.Sh DESCRIPTION 54The | 1.\" Copyright (c) 1992, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" This code is derived from software contributed to Berkeley by 5.\" the Institute of Electrical and Electronics Engineers, Inc. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions --- 38 unchanged lines hidden (view full) --- 47.Op Ar file ... 48.Nm sed 49.Op Fl an 50.Op Fl e Ar command 51.Op Fl f Ar command_file 52.Op Ar file ... 53.Sh DESCRIPTION 54The |
55.Nm sed | 55.Nm |
56utility reads the specified files, or the standard input if no files 57are specified, modifying the input as specified by a list of commands. 58The input is then written to the standard output. 59.Pp 60A single command may be specified as the first argument to 61.Nm sed . 62Multiple commands may be specified by using the 63.Fl e --- 8 unchanged lines hidden (view full) --- 72.It Fl a 73The files listed as parameters for the 74.Dq w 75functions are created (or truncated) before any processing begins, 76by default. 77The 78.Fl a 79option causes | 56utility reads the specified files, or the standard input if no files 57are specified, modifying the input as specified by a list of commands. 58The input is then written to the standard output. 59.Pp 60A single command may be specified as the first argument to 61.Nm sed . 62Multiple commands may be specified by using the 63.Fl e --- 8 unchanged lines hidden (view full) --- 72.It Fl a 73The files listed as parameters for the 74.Dq w 75functions are created (or truncated) before any processing begins, 76by default. 77The 78.Fl a 79option causes |
80.Nm sed | 80.Nm |
81to delay opening each file until a command containing the related 82.Dq w 83function is applied to a line of input. 84.It Fl e Ar command 85Append the editing commands specified by the 86.Ar command 87argument 88to the list of commands. --- 6 unchanged lines hidden (view full) --- 95By default, each line of input is echoed to the standard output after 96all of the commands have been applied to it. 97The 98.Fl n 99option suppresses this behavior. 100.El 101.Pp 102The form of a | 81to delay opening each file until a command containing the related 82.Dq w 83function is applied to a line of input. 84.It Fl e Ar command 85Append the editing commands specified by the 86.Ar command 87argument 88to the list of commands. --- 6 unchanged lines hidden (view full) --- 95By default, each line of input is echoed to the standard output after 96all of the commands have been applied to it. 97The 98.Fl n 99option suppresses this behavior. 100.El 101.Pp 102The form of a |
103.Nm sed | 103.Nm |
104command is as follows: 105.sp 106.Dl [address[,address]]function[arguments] 107.sp 108Whitespace may be inserted before the first address and the function 109portions of the command. 110.Pp 111Normally, | 104command is as follows: 105.sp 106.Dl [address[,address]]function[arguments] 107.sp 108Whitespace may be inserted before the first address and the function 109portions of the command. 110.Pp 111Normally, |
112.Nm sed | 112.Nm |
113cyclically copies a line of input, not including its terminating newline 114character, into a 115.Em "pattern space" , 116(unless there is something left after a 117.Dq D 118function), 119applies all of the commands with addresses that select that pattern space, 120copies the pattern space to the standard output, appending a newline, and --- 19 unchanged lines hidden (view full) --- 140that match the address. 141.Pp 142A command line with two addresses selects the inclusive range from 143the first pattern space that matches the first address through the next 144pattern space that matches the second. 145(If the second address is a number less than or equal to the line number 146first selected, only that line is selected.) 147Starting at the first line following the selected range, | 113cyclically copies a line of input, not including its terminating newline 114character, into a 115.Em "pattern space" , 116(unless there is something left after a 117.Dq D 118function), 119applies all of the commands with addresses that select that pattern space, 120copies the pattern space to the standard output, appending a newline, and --- 19 unchanged lines hidden (view full) --- 140that match the address. 141.Pp 142A command line with two addresses selects the inclusive range from 143the first pattern space that matches the first address through the next 144pattern space that matches the second. 145(If the second address is a number less than or equal to the line number 146first selected, only that line is selected.) 147Starting at the first line following the selected range, |
148.Nm sed | 148.Nm |
149starts looking again for the first address. 150.Pp 151Editing commands can be applied to non-selected pattern spaces by use 152of the exclamation character 153.Po 154.Dq ! 155.Pc 156function. 157.Sh "Sed Regular Expressions" 158The | 149starts looking again for the first address. 150.Pp 151Editing commands can be applied to non-selected pattern spaces by use 152of the exclamation character 153.Po 154.Dq ! 155.Pc 156function. 157.Sh "Sed Regular Expressions" 158The |
159.Nm sed | 159.Nm |
160regular expressions are basic regular expressions (BRE's, see 161.Xr regex 3 162for more information). 163In addition, | 160regular expressions are basic regular expressions (BRE's, see 161.Xr regex 3 162for more information). 163In addition, |
164.Nm sed | 164.Nm |
165has the following two additions to BRE's: 166.sp 167.Bl -enum -compact 168.It 169In a context address, any character other than a backslash 170.Po 171.Dq \e 172.Pc --- 11 unchanged lines hidden (view full) --- 184.It 185The escape sequence \en matches a newline character embedded in the 186pattern space. 187You can't, however, use a literal newline character in an address or 188in the substitute command. 189.El 190.Pp 191One special feature of | 165has the following two additions to BRE's: 166.sp 167.Bl -enum -compact 168.It 169In a context address, any character other than a backslash 170.Po 171.Dq \e 172.Pc --- 11 unchanged lines hidden (view full) --- 184.It 185The escape sequence \en matches a newline character embedded in the 186pattern space. 187You can't, however, use a literal newline character in an address or 188in the substitute command. 189.El 190.Pp 191One special feature of |
192.Nm sed | 192.Nm |
193regular expressions is that they can default to the last regular 194expression used. 195If a regular expression is empty, i.e. just the delimiter characters 196are specified, the last regular expression encountered is used instead. 197The last regular expression is defined as the last regular expression 198used as part of an address or substitute command, and at run-time, not 199compile-time. 200For example, the command --- 16 unchanged lines hidden (view full) --- 217.Pp 218The 219.Dq r 220and 221.Dq w 222functions take an optional file parameter, which should be separated 223from the function letter by white space. 224Each file given as an argument to | 193regular expressions is that they can default to the last regular 194expression used. 195If a regular expression is empty, i.e. just the delimiter characters 196are specified, the last regular expression encountered is used instead. 197The last regular expression is defined as the last regular expression 198used as part of an address or substitute command, and at run-time, not 199compile-time. 200For example, the command --- 16 unchanged lines hidden (view full) --- 217.Pp 218The 219.Dq r 220and 221.Dq w 222functions take an optional file parameter, which should be separated 223from the function letter by white space. 224Each file given as an argument to |
225.Nm sed | 225.Nm |
226is created (or its contents truncated) before any input processing begins. 227.Pp 228The 229.Dq b , 230.Dq r , 231.Dq s , 232.Dq t , 233.Dq w , 234.Dq y , 235.Dq ! , 236and 237.Dq \&: 238functions all accept additional arguments. 239The following synopses indicate which arguments have to be separated from 240the function letters by white space characters. 241.Pp 242Two of the functions take a function-list. 243This is a list of | 226is created (or its contents truncated) before any input processing begins. 227.Pp 228The 229.Dq b , 230.Dq r , 231.Dq s , 232.Dq t , 233.Dq w , 234.Dq y , 235.Dq ! , 236and 237.Dq \&: 238functions all accept additional arguments. 239The following synopses indicate which arguments have to be separated from 240the function letters by white space characters. 241.Pp 242Two of the functions take a function-list. 243This is a list of |
244.Nm sed | 244.Nm |
245functions separated by newlines, as follows: 246.Bd -literal -offset indent 247{ function 248 function 249 ... 250 function 251} 252.Ed --- 235 unchanged lines hidden (view full) --- 488.Dq #n , 489the default output is suppressed. 490This is the same as specifying the 491.Fl n 492option on the command line. 493.El 494.Pp 495The | 245functions separated by newlines, as follows: 246.Bd -literal -offset indent 247{ function 248 function 249 ... 250 function 251} 252.Ed --- 235 unchanged lines hidden (view full) --- 488.Dq #n , 489the default output is suppressed. 490This is the same as specifying the 491.Fl n 492option on the command line. 493.El 494.Pp 495The |
496.Nm sed | 496.Nm |
497utility exits 0 on success and >0 if an error occurs. 498.Sh SEE ALSO 499.Xr awk 1 , 500.Xr ed 1 , 501.Xr grep 1 , 502.Xr regex 3 , 503.Xr re_format 7 504.Sh HISTORY 505A | 497utility exits 0 on success and >0 if an error occurs. 498.Sh SEE ALSO 499.Xr awk 1 , 500.Xr ed 1 , 501.Xr grep 1 , 502.Xr regex 3 , 503.Xr re_format 7 504.Sh HISTORY 505A |
506.Nm sed | 506.Nm |
507command appeared in 508.At v7 . 509.Sh STANDARDS 510The | 507command appeared in 508.At v7 . 509.Sh STANDARDS 510The |
511.Nm sed | 511.Nm |
512function is expected to be a superset of the 513.St -p1003.2 514specification. | 512function is expected to be a superset of the 513.St -p1003.2 514specification. |