8.4.28 sed command (replaces character strings in text)
Syntax
sed [-a] [-E] [-n] [-r] [-u] command [input-file-path-name...] sed [-a] [-E] [-n] [-r] [-u] [-e command]... [-f script-file-path-name]... [input-file-path-name...]
Description
This command sends text from a file or the standard input to the standard output with specified character strings replaced.
Arguments
- -a
Specifies that if a parsing error occurs in an editing command, no new file is to be created nor is any existing file to be overwritten (which could otherwise occur unintentionally). This option is used to maintain control over when the pattern space output file used by the w command or by the s command's w flag is created. The pattern space output file is created when the w command or the s command's w flag is applied. If the -a option is not specified, the pattern space output file is created during parsing of the w command or the s command's w flag.
- -E|-r
Specifies that any patterns specified in the command are to be handled as extended regular expressions. The -E and -r options function identically.
- -n
Specifies that output of the pattern space to the standard output is to be suppressed. When this option is specified, output of the pattern space to the standard output will not be performed unless the p or P command is executed.
- -u
In Windows, specifies that output buffering of the execution results to the standard output is to be suppressed.
In UNIX, specifies that the execution results are to be buffered on a per-record basis when output to the standard output.
- command|-e command
Specifies a command for editing the input file. More than one -e option can be specified. If you specify more than one -e option, the commands will be executed in the order they are specified. When the -f option is not used, command can be specified without the preceding -e option.
- -f script-file-path-name
Specifies the path name of a script file. The script file contains edit commands for editing the records in the input file. More than one -f option can be specified. If you specify more than one -f option, or if you specify a combination of multiple -f and -e options, the execution order of the commands will be the order in which they were specified.
- input-file-path-name
Specifies the path name of an input file to be edited. More than one input file path name can be specified. If no path name is specified, the standard input is read. If more than one file is specified, each file is opened when processing of the previous file reaches the end of the file, and reading of input records from the newly opened file begins.
Editing command description format
The following is the description format for an editing command for editing an input file:
[address[,address]] command[ arguments]
An address for identifying a record to be retrieved for editing can be specified in address. The address can be a record line number or a search pattern character string to be used for matching
The editing command to be applied to the retrieved records is specified in command.
Arguments to be passed to the editing command can be specified in arguments.
As each record is read from the input file, it is compared to the line number or search pattern character string specified in address. If there is a match, the editing specified in the command is performed. If address is omitted, all records will be retrieved as targets for editing. The results of executing the editing command are output to the standard output.
Addresses
Addresses are used to identify the records from the input file that are to be edited.
Line number
Specifies a line number, where 1 represents the first record of the input file. You can use the dollar sign ($) to indicate the last record. If multiple input files are specified, the records are numbered continuously across the multiple files. Note that if you specify 0 for the line number (or for the starting line number when specifying a range), the editing command will not be applied to any records.
Search pattern character string
Specifies a search pattern character string enclosed in forward slashes (/) for finding a matching character string in the input records. You can specify a regular expression for the search pattern character string. The following is an example for writing to a specified file the records that contain the character string abc:
/abc/w file
Instead of enclosing the search pattern character string in forward slashes (/), you can use any other single-byte character (except for \ or an end-of-line character). To use a separator other than the forward slash, specify a \ in front of the first separator.
The following is an example of changing the separator enclosing the search pattern character string from / to #.
\#abc#w file
Address range specification
You can use address, address to specify a range of records to be edited. The execution range for the editing command will begin with the record that matches the first address and conclude with the record that matches the second address.
A range can be specified as follows:
A range defined by two line numbers
A range defined by two search pattern character strings
A range defined by a combination of a line number and a search pattern character string
The following is an example of a range defined by two line numbers (this example writes to outfile the records in lines 5 through 20):
5,20w outfile
The execution range of the editing command begins with the record whose line number is specified in the first address and concludes with the record whose line number is specified in the second address.
Note that if the line number specified in the first address is greater than the line number specified in the second address (first address > second address), only the record corresponding to the line number specified in the first address will be subject to the editing command.
The following is an example of a range of two search pattern character strings:
/abc/, /xyz/w file
The execution range of the editing command begins with the record that matches the search pattern character string in the first address through and including the record that matches the search pattern character string in the second address.
If the search reaches the end of an input file without finding a record that contains the search pattern character string specified in the second address, the range concludes with the last line of the input file. However, if multiple input files are specified, the search for a record that matches the search pattern character string specified in the second address continues in the next input file.
If the first address is a search pattern character string and the second address is a line number and the line number of the record that matches the search pattern character string is greater than the line number in the second address (first address > second address), only the record matching the search pattern character string is subject to the editing command.
Pattern space and hold space
The sed command maintains two workspaces for text editing, called the pattern space and the hold space.
The pattern space stores records that are read from the input file.
The flow of processing in the pattern space is as follows:
Reads one record, delimited by the end-of-line code, from the input file.
In Windows, the end-of-line code is [CR] + [LF] or [LF]. In UNIX, the end-of-line code is [LF]. In UNIX, if the input file uses [CR] + [LF] for the end-of-line code, the [CR] is stored in the pattern space.
Copies the contents of the input record into the pattern space.
Executes the editing command if the pattern space includes a line number specified in the address or the search pattern character string matches a character string in the pattern space.
If the command to be executed is the D command and part of the input record remains in the pattern space after the D command has executed, steps 1 and 2 are skipped.
Outputs the contents of the pattern space to the standard output, unless the -n option has been specified.
Clears the contents of the pattern space.
The hold space is used as a temporary work area for operations such as saving the contents of the pattern space in the hold space and then returning the contents of the hold space to the pattern space.
Editing commands
The following editing commands can be used in sed:
- [address[,address]]{ command-list}
Creates a group of multiple editing commands that are to be applied to the matched input records. The editing commands are delimited by an end-of-line character or a semicolon (;). If a right curly bracket (}) is specified on the same line as the last editing command, there must be a semicolon after the command name.
[address]a\(end-of-line)
- text
Outputs the text set in text to the standard output before the next input record is read. To output multiple records, you must specify \ immediately before each end-of-line character.
In the following example, two records are sent to the standard output before the next input record is read.
a\(end-of-line) text1\(end-of-line) text2
- [address[,address]]b[label]
Branches to the :label command defined by the specified label label. If label is not specified, branching is to the end of the script.
[address[,address]]c\(end-of-line)
- text
Clears the contents of the pattern space. When no address or a single address is specified, the text expressed in text is sent to the standard output. When two addresses are specified, the text expressed in text is sent to the standard output after processing the last record in the selected range. If multiple records are output, you must specify \ immediately before each end-of-line character.
After the pattern space is cleared, the next input record is read and execution restarts from the beginning, without executing any commands that appear after the c command.
- [address[,address]]d
Clears the contents of the pattern space. The contents of the pattern space are sent to the standard output before the pattern space is cleared. Then the next input record is read and execution restarts from the beginning, without executing any commands that appear after the d command.
- [address[,address]]D
When the pattern space holds multiple records, deletes everything up to the first end-of-line character. The contents of the pattern space are not sent to the standard output. The next input record is then read and execution restarts from the beginning, without executing any commands that appear after the D command.
If the pattern space is empty as a result of executing the D command, the next input record is read and execution restarts from the beginning of the command.
- [address[,address]]g
Copies the contents of the hold space into the pattern space. The previous contents of the pattern space are discarded.
- [address[,address]]G
Appends the contents of the hold space to the pattern space, separated from the records already stored in the pattern space by the end-of-line character.
- [address[,address]]h
Copies the contents of the pattern space into the hold space. The previous contents of the hold space are discarded.
- [address[,address]]H
Appends the contents of the pattern space to the hold space, separated from the records already stored in the hold space by the end-of-line character.
[address]i\(end-of-line)
- text
Sends the text expressed in text to the standard output before storing the current input record in the pattern space. To output multiple records, you must specify a backslash (\) immediately before each end-of-line character.
- [address[,address]]l
Sends the contents of the pattern space to the standard output. For data other than single-byte characters (in the range 0x20 to 0x7e), the space, and multibyte characters, each byte is output as a three-digit octal number preceded by a backslash (\). The backslash itself is output as \\, and the control codes shown in the following table are output as escape characters.
Control code
Escape character that is output
Alert character (bell)
\a
Backspace character
\b
Formfeed character (page break)
\f
End-of-line character. Note that the end-of-line character at the end of a lone line (or of the last line in the case of multiple lines) is not output.
\n
Carriage return character
\r
Tab character
\t
Vertical tab character
\v
The value for the output width of a record is determined in the following priority order:
Value of the COLUMNS environment variable
For output to the console, width of the console screen
60 single-byte characters
The dollar sign ($) is output at the end of each record. If a record exceeds the output width, it is split and a backslash (\) is set at the split location.
- [address[,address]]n
Sends the current contents of the pattern space to the standard output and then reads the next input record from the input file and stores it in the pattern space. The current line number is incremented by 1. If the -n option was specified, the current contents of the pattern space are not sent to the standard output.
- [address[,address]]N
Reads the next input record from the input file and appends it to the pattern space, separated from the records already stored in the pattern space by the end-of-line character. The current line number is incremented by 1.
- [address[,address]]p
Sends the contents of the pattern space to the standard output.
- [address[,address]]P
If the pattern space contains multiple records, outputs the contents only up to the first end-of-line character. If the pattern space contains only one record, this command is the same as the p command.
- [address]q
Terminates processing of the script. No further execution of commands or reading of input records is performed after this command. Unless the -n option was specified, the contents of the pattern space are sent to the standard output at the time of termination. In addition, any records that had been added using the a or r command are output.
- [address]r path-name
Before reading the next input record, reads the file specified in path-name and outputs its contents to the standard output. Any errors that occur during input of the file specified in path-name are ignored.
In Windows, end-of-line codes in the file are output as [CR] + [LF].
In UNIX, end-of-line codes in the file are output as is.
- [address[,address]]s/pattern/replacement/flags
Substitutes the replacement character string (replacement) for the first character string that matches the pattern (pattern) in the pattern space. Instead of using a forward slash (/) to separate s, pattern, and replacement, you can use any single-byte character except for a backslash (\) or the end-of-line character. To include the separator character within pattern or replacement, it must be preceded by a backslash (\).
You can specify a regular expression for pattern.
The following characters can be used in the replacement character string for the indicated purposes:
&: The ampersand (&) is replaced by the character string that matches pattern. To handle an & as a character to be replaced, it must be preceded by a backslash (\).
\N (where N is a digit from 1 through 9): The \N is replaced by the character string that matches a tagged regular expression enclosed in parentheses (( )) in pattern. The numeric digit (N) specifies the sequential order of the tagged regular expression to be matched.
\: To include an end-of-line code, specify backslash (\) immediately before the end-of-line code.
The flags that can be specified in flags include the values shown below. The flags are optional. More than one can be specified.
- N
Only replace the N-th matched pattern in the pattern space.
- g
Globally replace all the character strings that match the pattern in the pattern space, not just the first one.
- p
If any substitution was made, output the contents of the pattern space to the standard output.
- w path-name
If any substitution was made, output the contents of the pattern space to the file specified in path-name. If an existing file is specified in path-name, the following occurs:
- If the -a option was not specified
Regardless of whether a substitution was made, the prior contents before execution of the sed command are discarded.
- If the -a option was specified
If a substitution was made, the prior contents before execution of the sed command are discarded.
In Windows, the end-of-line code for the file is output as [CR] + [LF].
- [address[,address]]t[label]
Branches to the : (colon) command defined by the specified label (label) if a substitution has been performed by the s command since the last input record was read or since the previously-executed t command was executed. If no label is specified, branching is to the end of the script.
- [address[,address]] w path-name
Writes the contents of the pattern space to the file specified in path-name. If an existing file is specified in path-name, the following occurs:
If the -a option was not specified
Regardless of whether there is a match with the address (address), the prior contents before execution of the sed command are discarded.
If the -a option was specified
If there is a match with the address (address), the prior contents before execution of the sed command are discarded.
In Windows, the end-of-line code for the file is output as [CR] + [LF].
- [address[,address]]x
Exchanges the contents of the pattern space and the contents of the hold space.
- [address[,address]]y/string1/string2/
Searches the contents of the pattern space and replaces each character string specified in string1 with the character string specified in string2 (this is a character-by-character replacement, so each character position in string1 is replaced with the character at the corresponding position in string2).
The number of characters in string1 and string2 must be the same.
To specify an end-of-line character in string1 or string2, specify \n. Instead of using a / to separate y, string1, and string2, you can use any other single-byte character except for \ or the end-of-line character.
- [address[,address]]!command or [address[,address]]!{command-list}
Applies the command, or list of grouped commands, to the records that are not selected by the address (address).
- :label
Defines a label for the branch destinations specified in the b and t commands. The : (colon) command itself performs no processing.
- [address]=
Outputs the current line number to the standard output as a single record.
- (blank line)
Blank lines are ignored.
- #
Indicates a comment. The hash mark (#) and everything following it is treated as a comment. Note that if the first column of the first record of the script file begins with #n, the -n option is assumed.
Escape characters
The escape characters listed below can be used within an address search pattern, the text portion of the a, c, and i commands, pattern and replacement character strings of the s command, and the search characters and replacement characters of the y command.
Escape character |
Meaning |
---|---|
\a |
Alert character (bell) |
\b |
Backspace character#1 |
\f |
Formfeed character (page break) |
\n |
End-of-line character#2 |
\r |
Carriage return character |
\t |
Tab character |
\v |
Vertical tab character |
\xhex |
Character represented by a one- or two-digit hexadecimal value (0 to 9, a to f, A to F)#3 |
\c |
Any literal character (for example, \" for ") |
\\ |
A single backslash character |
- #1
If you specify this in an address search pattern or in the pattern in the s command, it is treated as the \b regular expression operator. However, if you specify it in a character class enclosed in square brackets ([ ]), it is treated as the backspace character.
- #2
In Windows, this is output as [CR] + [LF] when specified within the text portion of the a, c, and i commands.
- #3
There are values that cannot be specified in a pattern depending on the character encoding at the time of execution. The values that can be specified for each character encoding are listed below in hexadecimal. Execution terminates with an error if you specify any other value.
Shift JIS
0x01-0x80, 0xA0-0xDF, 0xFD-0xFF
UTF-8
0x01-0xBF, 0xFE-0xFF
EUC
0x01-0x8D, 0x90-0xA0, 0xFF
C
0x01-0xFF
Return codes
Return code |
Meaning |
---|---|
0 |
Normal termination |
1 or greater |
Error termination |
Examples
Specify the d command to delete the first through third records of the file. The input file is file01.txt.
Contents of file01.txt:
hitachi group01 Tokyo HITACHI group02 Yokohama hitachi group03 Fukuoka HITACHI group04 Hokkaido HITACHI group05 Ooita HITACHI group06 Hiroshima
The results of executing the command are as follows:
C:\DIR>%ADSH_OSCMD_DIR%\sed "1,3d" file01.txt HITACHI group04 Hokkaido HITACHI group05 Ooita HITACHI group06 Hiroshima
Search for a pattern and then use the i command to add two records before each matched record and the a command to add one record before each matched record. In addition, use the c command to replace with another record each record that does not match the search pattern. The script file is scpt01.sed, and the input file is file02.txt.
Contents of scpt01.sed:
/file/{ i\ <FILE-LINE>\ [FILE-BEGIN] a\ [FILE-END] } /file/!{ c\ <DIR-LINE> }
Contents of file02.txt:
The file path used by trace is invalid. Don't know current directory. Input asc file is the same as output asc file. Cannot change directory. Merging two asc files is started.
The results of executing the command are as follows:
C:\DIR>%ADSH_OSCMD_DIR%\sed -f scpt01.sed file02.txt <FILE-LINE> [FILE-BEGIN] The file path used by trace is invalid. [FILE-END] <DIR-LINE> <FILE-LINE> [FILE-BEGIN] Input asc file is the same as output asc file. [FILE-END] <DIR-LINE> <FILE-LINE> [FILE-BEGIN] Merging two asc files is started. [FILE-END]
Replace the first character string that matches a pattern. The input file is file03.txt.
Contents of file03.txt:
Hitachi Yokohama Office Hitachi Group Hitachi Tokyo Office Hitachi Group Hitachi Okinawa Office Hitachi Group Hitachi Fukuoka Office Hitachi Group
The results of executing the command are as follows:
C:\DIR>%ADSH_OSCMD_DIR%\sed "s/Hitachi/& Corporation/" file03.txt Hitachi Corporation Yokohama Office Hitachi Group Hitachi Corporation Tokyo Office Hitachi Group Hitachi Corporation Okinawa Office Hitachi Group Hitachi Corporation Fukuoka Office Hitachi Group
Format the output by replacing character strings that match a pattern. The input file is file04.txt.
Contents of file04.txt:
Hitachi Yokohama Office Hitachi Group Hitachi Tokyo Office Hitachi Group Hitachi Okinawa Office Hitachi Group Hitachi Hokkaido Office Hitachi Group Hitachi Fukuoka Office Hitachi Group
The results of executing the command are as follows:
C:\DIR>%ADSH_OSCMD_DIR%\sed "s/\(Hitachi \)\(.*\) \(Office\)/\1\3 name: \2/" file04.txt Hitachi Office name: Yokohama Hitachi Group Hitachi Office name: Tokyo Hitachi Group Hitachi Office name: Okinawa Hitachi Group Hitachi Office name: Hokkaido Hitachi Group Hitachi Office name: Fukuoka Hitachi Group
Replace the second character string that matches a pattern. The input file is file05.txt.
Contents of file05.txt:
Hitachi Yokohama Office Hitachi Group Hitachi Corporation Hitachi Tokyo Office Hitachi Group Hitachi Corporation Hitachi Okinawa Office Hitachi Group Hitachi Corporation Hitachi Fukuoka Office Hitachi Group Hitachi Corporation
The results of executing the command are as follows:
C:\DIR>%ADSH_OSCMD_DIR%\sed "s/Hitachi/& Corporation/2" file05.txt Hitachi Yokohama Office Hitachi Corporation Group Hitachi Corporation Hitachi Tokyo Office Hitachi Corporation Group Hitachi Corporation Hitachi Okinawa Office Hitachi Corporation Group Hitachi Corporation Hitachi Fukuoka Office Hitachi Corporation Group Hitachi Corporation
Replace all character strings that match a pattern in the records in a specified range. The input file is file06.txt.
Contents of file06.txt:
Hitachi Yokohama Office Hitachi Group Hitachi Tokyo Office Hitachi Group Hitachi Okinawa Office Hitachi Group Hitachi Fukuoka Office Hitachi Group
The results of executing the command are as follows:
C:\DIR>%ADSH_OSCMD_DIR%\sed "/Tokyo/, /Okinawa/s/Hitachi/& Corporation/g" file06.txt Hitachi Yokohama Office Hitachi Group Hitachi Corporation Tokyo Office Hitachi Corporation Group Hitachi Corporation Okinawa Office Hitachi Corporation Group Hitachi Fukuoka Office Hitachi Group
Specify the p flag to the s command to output to the standard output the records in which a substitution occurred. The input file is file07.txt.
Contents of file07.txt:
Hitachi Yokohama Office Hitachi Group Hitachi Tokyo Office Hitachi Group Hitachi Okinawa Office Hitachi Group Hitachi Fukuoka Office Hitachi Group
Examples of executing the command are given below.
Example output with the -n option
C:\DIR>%ADSH_OSCMD_DIR%\sed -n "/Tokyo/, /Okinawa/s/Hitachi/& Corporation/gp" file07.txt Hitachi Corporation Tokyo Office Hitachi Corporation Group Hitachi Corporation Okinawa Office Hitachi Corporation Group
Example output without the -n option
C:\DIR>%ADSH_OSCMD_DIR%\sed "/Tokyo/, /Okinawa/s/Hitachi/& Corporation/gp" file07.txt Hitachi Yokohama Office Hitachi Group Hitachi Corporation Tokyo Office Hitachi Corporation Group Hitachi Corporation Tokyo Office Hitachi Corporation Group Hitachi Corporation Okinawa Office Hitachi Corporation Group Hitachi Corporation Okinawa Office Hitachi Corporation Group Hitachi Fukuoka Office Hitachi Group
Specify the w flag to the s command to output to a file the records in which a substitution occurred. The input file is file08.txt.
Contents of file08.txt:
Hitachi Yokohama Office Hitachi Group Hitachi Tokyo Office Hitachi Group Hitachi Okinawa Office Hitachi Group Hitachi Fukuoka Office Hitachi Group
The results of executing the command are as follows:
C:\DIR>%ADSH_OSCMD_DIR%\sed -n "/Tokyo/, /Okinawa/s/Hitachi/& Corporation/gw dir\\out.txt" file08.txt C:\DIR>%ADSH_OSCMD_DIR%\cat dir\out.txt Hitachi Corporation Tokyo Office Hitachi Corporation Group Hitachi Corporation Okinawa Office Hitachi Corporation Group
Output to a file the records not found within a specified range. The input file is file09.txt.
Contents of file09.txt:
Hitachi Yokohama Office Hitachi Group Hitachi Tokyo Office Hitachi Group Hitachi Hokkaido Office Hitachi Group Hitachi Okinawa Office Hitachi Group Hitachi Fukuoka Office Hitachi Group
The results of executing the command are as follows:
C:\DIR>sed -n "/Tokyo/, /Okinawa/!w dir\\out.txt" file09.txt C:\DIR>cat dir\out.txt Hitachi Yokohama Office Hitachi Group Hitachi Fukuoka Office Hitachi Group
Use the y command to substitute characters. The input file is file10.txt.
Contents of file10.txt:
a b c d e a b c e d c b a
The results of executing the command are as follows:
C:\DIR>%ADSH_OSCMD_DIR%\sed "y/abcde/12345/" file10.txt 1 2 3 4 5 1 2 3 5 4 3 2 1
Output to the standard output the records that match a search pattern and their line numbers. Because the first record of the script file begins with #n, records that do not match the search pattern are not output. The script file is scpt02.sed, and the input file is prog01.awk.
Contents of scpt02.sed:
#n / print/{ = p }
Contents of prog01.awk:
BEGIN{ print "Extract record : group03 - group06" > "file06.txt" } /group03/, /group06/{# count++; print >> "file06.txt"; } END{ printf "total record : %03d\n", count >> "file06.txt" }
- #
The processing target begins with the record that matches group03 and concludes with the record that matches group06.
The results of executing the command are as follows:
C:\DIR>%ADSH_OSCMD_DIR%\sed -f scpt02.sed prog01.awk 2 print "Extract record : group03 - group06" > "file06.txt" 6 print >> "file06.txt"; 10 printf "total record : %03d\n", count >> "file06.txt"
Use the 1 command so that unprintable and escape characters will be visible in the output. The input file is file11.txt.
Contents of file11.txt:
Hitachi(tab)Yokohama\Office(tab)HitachiGroup Hitachi(tab)Tokyo\Office(tab)HitachiGroup Hitachi(tab)Fukuoka\Office(tab)Hitachi(0x12)#Group
- #
1 byte of data.
The results of executing the command are as follows:
C:\DIR>%ADSH_OSCMD_DIR%\sed -n "l" file11.txt Hitachi\tYokohama\\Office\tHitachiGroup$ Hitachi\tTokyo\\Office\tHitachiGroup$ Hitachi\tFukuoka\\Office\tHitachi\022Group$
Read the contents of the file specified by the r command at the location of the record that matches the search pattern, and then use the d command to delete the record that matches the search pattern. The script file is scpt03.sed, and the input files are prog02.awk and header.txt.
Contents of scpt03.sed:
/^<Header>/{ r header.txt d }
Contents of prog02.awk:
################################################################### <Header> ################################################################### BEGIN{ str = "Hitachi#YokohamaOffice#HitachiGroup" num = split(str, arry, "#") for (i = 1; i <= num; i++ ) { print arry[i] } }
Contents of header.txt:
# Sample program # Hitachi group list
The results of executing the command are as follows:
C:\DIR>%ADSH_OSCMD_DIR%\sed -f scpt03.sed prog02.awk ################################################################### # Sample program # Hitachi group list ################################################################### BEGIN{ str = "Hitachi#YokohamaOffice#HitachiGroup" num = split(str, arry,"#") for (i = 1; i <= num; i++ ) { print arry[i] } }
Extract blocks of records from a file. The script file is scpt04.sed, and the input file is file12.txt.
Contents of scpt04.sed:
/^Error01/{ :LOOP n#1 /Error/{ /^Error01/b LOOP#2 /^Error01/!d } b LOOP#2 } d
- #1
This outputs the current contents of the pattern space to the standard output and then reads the next record.
- #2
This branches to the LOOP label to execute the n command to read the next record.
Contents of file12.txt:
Error01001 The file path used by trace is invalid. Error02001 Don't know current directory. Error01002 Unable to get the date for the start of the job execution. Spool job was not deleted. Error01003 Cannot change directory. Error02002 Asc file name size is exceeded limits for batch coverage function. Error01004 Failed to get the current time.
The results of executing the command are as follows:
C:\DIR>%ADSH_OSCMD_DIR%\sed -f scpt04.sed file12.txt Error01001 The file path used by trace is invalid. Error01002 Unable to get the date for the start of the job execution. Spool job was not deleted. Error01003 Cannot change directory. Error01004 Failed to get the current time.
Use the q command to terminate the script after reading a record that matches the pattern. The input file is file13.txt.
Contents of file13.txt:
Error01001 The file path used by trace is invalid. Error02001 Don't know current directory. Error01002 Unable to get the date for the start of the job execution. Spool job was not deleted. Error01003 Cannot change directory.
The results of executing the command are as follows:
C:\DIR>%ADSH_OSCMD_DIR%\sed "/Error01002/q" file13.txt Error01001 The file path used by trace is invalid. Error02001 Don't know current directory. Error01002
Display an option error message.
This message might vary depending on the platform on which the command is executed. The following shows an example in Windows:
C:\TEMP>%ADSH_OSCMD_DIR%\sed -x sed: illegal option -- x usage: sed [-aEnru] command [file ...] sed [-aEnru] [-e command] ... [-f command_file] ... [file ...]