DOS命令大全:Edlin:r (replace)命令详解
3736 点击·0 回帖
![]() | ![]() | |
![]() | 在相邻行块中搜索指定的一个或多个字符组成的字符串,并用指定的另一个字符串替换每次找到的那个字符串。 MS-DOS命令语法 [line1][,line2][?]r[string1][CTRL+Z string2] MS-DOS命令参数 line1指定在其中要替换 string1中指定的字符串的第一行。line2指定在其中要替换 string1中指定的字符串的最后一行。?在 Edlin.exe 替换 string1中指定的字符串之前,发送确认信息。string1指定要替换的字符串。Ctrl + Z分隔 string1 和 string2 值。此参数的唯一有效值是文件结束符 (CTRL+Z),表示为^Z。string2指定新字符串,用于替换 string1中所指定字符串的每个字符串。MS-DOS命令注释 新的当前行是 Edlin.exe 在其中替换 string1 的最后一行。 命令行间隔在命令行上的 r 和任何后续的参数之间不能插入空格。 忽略参数如果省略 line1,Edlin.exe 将从当前行之后的一行开始搜索。如果省略 line2,Edlin.exe 将在文件末尾或内存中当前存在的文本的末尾停止搜索。 如果省略 string1,Edlin.exe 将使用下列两个值中最近使用过的那个:此会话期间最近一次使用 r 时为 string1 所指定的值,或最近一次使用 s 时为字符串所指定的值。如果省略 string1 并且在当前编辑会话期间未使用 r 或 s 子命令,则 r 子命令将立即停止。 如果省略 string2 参数,Edlin.exe 将使用最近一次在会话过程中使用 r 命令所指定的值。如果省略 string2,并且在当前会话过程中还未使用 r 命令,Edlin.exe 将删除所有指定的 string1 字符串。 使用 CTRL+Z必须使用 CTRL+Z 将 string1 值和 string2 值独立开来,如果省略 string1,仍然需要按 CTRL+Z 来标记 string2 的开头。当按 CTRL+Z 时,出现如下字符: ^Z 使用问号 (?) 参数如果您的命令中包含 ?参数,Edlin.exe 显示行,此行包含首次出现的、为 string1 指定字符串的行,并通过显示下列确认消息提示您: O.K.? 如果按“Y”(是)或 ENTER 键,Edlin.exe 将用 string2 的值替换搜索到的 string1,并查找下一个。如果按“N”(否),Edlin.exe 将不替换搜索到的 string1,而是查找下一个。 如果在替换时不使用 ? 参数确认替换,Edlin.exe 将立即替换所有的 string1,然后显示包含替换的各行。如果行包含了两个或多个替换,Edlin.exe 将为每个替换显示该行一次。 MS-DOS命令范例 要用词“ours”替换内存中编辑文件的前 20 行中的每个“mine”,同时接收确认消息,请键入(不要按 ENTER 键): 1,20?rmineCTRL+Zours CTRL+Z 以^Z 的形式出现在屏幕上。该命令在屏幕上显示以下内容: 1,20?rmine^Zours 在本示例中,以下文件在内存中并准备编辑。当在 * 提示符下使用 l (list) 子命令时,Edlin.exe 将显示文件的内容。 1: Dear Mr. Muth: 2: 3: Congratulations on your promotion 4:to the position of Senior Chemical 5:EngineerI continue to be most 6:impressed with your fine work. 7: 8: I think you will enjoy working with 9:Mr. Lang on the new project.Please 10:let me know if there is anything I 11:can do to assist you. 13: Sincerely, 14: 15: Clay Martin, President 16:Contoso, Ltd 17:"A World Leader in Technology" 要用词组“yours truly”替换第 5 到 10 行中的所有单词“I”,同时不接收确认消息,请键入: 5,10rICTRL+Zyours truly CTRL+Z 以^Z 的形式出现在屏幕上。该命令在屏幕上显示以下内容: 5,10rI^Zyours truly 由于您未包括 ?参数,Edlin.exe 将替换三个“I”,而不显示确认消息。当 Edlin.exe 完成执行命令后,它显示下列行,这些行已更改为三个替换的结果: 5: Engineer. yours truly continue to be most 8:yours truly think you will enjoy working with 10:let me know if there is anything yours truly 在上例中,第 5 行和第 8 行中出现了两个无意的替换。添加 ? 可以避免这种更改。该命令的参数。完成的命令应在屏幕上显示以下内容: 5,10?rI^Zyours truly 每次出现 string1中指定的字符串时,Edlin.exe 会通过显示确认消息来提示您,并且只执行经确认的替换,如下例所示: 5: Engineer. yours truly continue to be most O.K.? n 8:yours truly think you will enjoy working with O.K.? n 10:let me know if there is anything yours truly O.K.? y 当您使用 ?参数时,Edlin.exe 不会自动显示 Edlin.exe 作为确认替换结果更改的行。如果在 * 提示符下键入 l (list) 子命令,Edlin.exe 将显示内存中的编辑文件,如下所示: 1: Dear Mr. Muth: 2: 3: Congratulations on your promotion 4:to the position of Senior Chemical 5:EngineerI continue to be most 6:impressed with your hard work. 7: 7: 8: I think you will enjoy working with 9:Mr. Lang on the new project.Please 10:let me know if there is anything yours truly 11:can do to assist you. 13: Sincerely, 14: 15: Clay Martin, President 16:Contoso, Ltd 17:"A World Leader in Technology" | |
![]() | ![]() |