当前位置: 首页 > news >正文

找室内效果图的网站建站工具免费

找室内效果图的网站,建站工具免费,医学教育网站建设方案,昆山企业网站建设Linux命令行与Shell脚本编程 第十八章 文本处理与编辑器基础 文章目录 Linux命令行与Shell脚本编程第十八章 文本处理与编辑器基础 文本处理与编辑器基础8.1.文本处理8.1.1.sed编辑器8.1.1.1.在命令行中定义编辑器命令8.1.1.2.在命令行中使用多个编辑器命令8.1.1.3.从文件中读…Linux命令行与Shell脚本编程 第十八章 文本处理与编辑器基础 文章目录 Linux命令行与Shell脚本编程第十八章 文本处理与编辑器基础 文本处理与编辑器基础8.1.文本处理8.1.1.sed编辑器8.1.1.1.在命令行中定义编辑器命令8.1.1.2.在命令行中使用多个编辑器命令8.1.1.3.从文件中读取编辑器命令 8.1.2.gawk编辑器8.1.2.1.gawk命令格式8.1.2.2.从命令行读取gawk脚本8.1.2.3.使用数据字段变量8.1.2.4.在脚本中使用多条命令8.1.2.5.从文件中读取脚本8.1.2.6.在处理数据前运行脚本8.1.2.7.在处理数据后运行脚本 8.2.sed编辑器基础命令8.2.1.更多的替换选项8.2.1.1.替换标志8.2.1.2.替换字符 8.2.2.使用地址8.2.2.1.数字形式行寻址8.2.2.2.使用文本模式过滤8.2.2.3.命令组 8.2.3.删除行(d)8.2.4.插入和附加文本(a\i)插入与附加添加多行 8.2.5.修改行(c)8.2.6.转换命令(y)8.2.7.打印打印行(p)打印行号()列出行(l) 8.2.8.处理文件写入文件(w)读取数据(r)文件夹下文件 文本处理与编辑器基础 文本处理学习sed编辑器sed编辑器基础命令gawk编辑器入门sed编辑器基础 shell脚本可以将文本文件中各种数据的日常处理任务自动化Linux中的sed和gawk两款工具能够极大地简化数据处理任务。 8.1.文本处理 想要即时处理文本文件中的文本有一个可以自动格式化、插入、修改或删除文本元素的简单的命令行编辑器。 有两款常见工具sed和gawk。 8.1.1.sed编辑器 sed编辑器stream editor流编辑器. 在交互式文本编辑器比如Vim中可以用键盘命令交互式地插入、删除或替换文本数据。 流编辑器则是根据事先设计好的一组规则编辑数据流。 sed编辑器根据命令来处理数据流中的数据命令可以从命令行中输入可以保存在命令文本文件中. sed编辑器可以执行下列操作: 从输入中读取一行数据。根据所提供的编辑器命令匹配数据。按照命令修改数据流中的数据。将新的数据输出到STDOUT。 在流编辑器匹配并对一行数据执行所有命令后会读取下一行数据并重复执行。在流编辑器处理完数据流中的所有行后就结束运行。 sed命令格式: sed options script fileoptions参数允许修改sed命令的行为: 选项描述-e commands处理输入时,加入额外的sed命令-f file处理输入时,将file中指定的命令添加到已有命令中-n不产生输出,使用p(print)命令完成输出 script参数指定了应用于流数据中的单个命令。 如果需要多个命令则使用-e选项在命令行中指定或使用-f选项在单独的文件中指定。 8.1.1.1.在命令行中定义编辑器命令 默认情况下sed编辑器会将指定的命令应用于STDIN输入流中。因此可以直接将数据通过管道传入sed编辑器进行处理. s 替换命令:替换命令会用斜线间指定的第二个字符串替换第一个字符串。 $ echo This is a test | sed s/test/big test/ This is a big testsed编辑器的强大之处是可以同时对数据做出多处修改. $ cat data1.txt The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. $ sed s/dog/cat/ data1.txt The quick brown fox jumps over the lazy cat. The quick brown fox jumps over the lazy cat. The quick brown fox jumps over the lazy cat. The quick brown fox jumps over the lazy cat.sed命令几乎瞬间就执行完毕并返回数据。在处理每行数据的同时结果也随之显现。在sed编辑器处理完整个文件之前就能看到结果。 重要的是sed编辑器并不会修改文本文件的数据。它只是将修改后的数据发送到STDOUT !!! 8.1.1.2.在命令行中使用多个编辑器命令 使用-e选项在sed命令行中执行多个命令. $ sed -e s/brown/red/; s/dog/cat/ data1.txt The quick red fox jumps over the lazy cat. The quick red fox jumps over the lazy cat. The quick red fox jumps over the lazy cat. The quick red fox jumps over the lazy cat.命令之间必须以分号 ; 分隔,命令末尾和分号之间不能出现空格。 也可以用bash shell中的次提示符来分隔命令。输入第一个单引号标示出sed程序脚本的起始. 要在闭合单引号所在行结束命令。bash shell一旦发现了闭合单引号就会执行命令. $ sed -e s/brown/green/s/fox/toad/s/dog/cat/ data1.txt The quick green toad jumps over the lazy cat. The quick green toad jumps over the lazy cat. The quick green toad jumps over the lazy cat. The quick green toad jumps over the lazy cat.8.1.1.3.从文件中读取编辑器命令 将量要执行的sed命令放进单独的文件通常会更方便. 在sed命令中用-f选项来指定文件 $ cat script1.sed s/brown/green/ s/fox/toad/ s/dog/cat/ $ sed -f script1.sed data1.txt The quick green toad jumps over the lazy cat. The quick green toad jumps over the lazy cat. The quick green toad jumps over the lazy cat. The quick green toad jumps over the lazy cat.不用在每条命令后面加分号。sed编辑器将每一行作为一条单独的命令。 sed编辑器脚本文件容易与bash shell脚本文件混淆。可以使用.sed作为sed脚本文件的扩展名。 更多sed命令 sed编辑器基础命令 8.1.2.gawk编辑器 虽然sed编辑器非常方便可以即时修改文本文件但其自身也存在一些局限。 往往还需要一款更高级的文本文件处理工具能够提供一个更贴近编程的环境修改和重新组织文件中的数据。 gawk是Unix中最初的awk的GNU版本。gawk比sed的流编辑提升了一个“段位”提供了一种编程语言而不仅仅是编辑器命令。 在gawk编程语言中可以实现: 定义变量来保存数据。使用算术和字符串运算符来处理数据。使用结构化编程概念比如if-then语句和循环为数据处理添加处理逻辑。提取文件中的数据将其重新排列组合最后生成格式化报告。 gawk的报告生成能力多用于从大文本文件中提取数据并将其格式化成可读性报告。 最完美的应用案例是格式化日志文件。gawk能够从日志文件中过滤出所需的数据将其格式化以便让重要的数据更易于阅读。 8.1.2.1.gawk命令格式 gawk options program file选项描述-F fs指定行中划分数据字段的字段分隔符-f file从指定文件中读物gawk脚本代码-v varvalue定义gawk脚本中的变量与默认值-L [keyword]指定gawk的兼容模式或警告级别 gawk可以编写脚本来读取文本行中的数据然后对其进行处理并显示形成各种输出报告。 8.1.2.2.从命令行读取gawk脚本 gawk脚本用一对花括号来定义。必须将脚本命令放到一对单引号与花括号 ‘{}’ 之间。 gawk命令行假定脚本是单个文本字符串因此必须将脚本放到单引号中。 没有在命令行中指定文件名时gawk程序会从STDIN接收数据。在脚本运行时会一直等待来自STDIN的文本。 $ gawk {print Hello World!} This is a test Hello World! hello Hello World! Goodbye Hello World! This is another test Hello World!脚本定义了一个命令print将文本打印到STDOUT。 在脚本运行时会一直等待来自STDIN的文本。如果输入一行文本并按下Enter键则gawk会对这行文本执行一遍脚本。 和sed编辑器一样gawk会对数据流中的每一行文本都执行脚本。 bash shell提供了CtrlD组合键来生成EOFend-of-file字符终止gawk程序表明数据流已经结束。 使用该组合键可以终止gawk程序并返回到命令行界面。 8.1.2.3.使用数据字段变量 gawk处理文本文件中的数据时会自动为每一行的各个数据元素分配一个变量。 在默认情况下gawk会将下列变量分配给文本行中的数据字段。 $0代表整个文本行。$n(1~n)代表文本行中的第n个数据字段。 文本行中的数据字段通过字段分隔符来划分。 读取一行文本时gawk会用预先定义好的字段分隔符划分出各个数据字段。默认是空白字符比如空格或制表符 使用$1字段变量来显示每行文本的第一个数据字段: $ cat data2.txt One line of test text. Two lines of test text. Three lines of test text. $ gawk {print $1} data2.txt One Two Three要读取的文件采用了其他的字段分隔符可以通过-F选项指定. 将冒号指定为字段分隔符-F:来显示了系统中密码文件的第一个数据字段. $ gawk -F: {print $1} /etc/passwd root daemon bin ... christine sshd8.1.2.4.在脚本中使用多条命令 将多条命令组合成一个常规的脚本,在命令之间加入分号. $ echo My name is Rich | gawk {$4Christine; print $0} My name is Christine或使用次提示符 $ gawk {$4 Christine print $0 } My name is Rich My name is Christine与sed类似,未指定文件时,会从STDIN读取输入,使用CtrlD生成EOF来结束脚本. 8.1.2.5.从文件中读取脚本 跟sed编辑器一样gawk允许将脚本保存在文件中然后在命令行中引用脚本. $ cat script2.gawk { print $1 s home directory is $6 } $ gawk -F: -f script2.gawk /etc/passwd roots home directory is /root daemons home directory is /usr/sbin bins home directory is /bin ... sshds home directory is /run/sshd可以在脚本文件中指定多条命令。 $ cat script3.gawk { text s home directory is print $1 text $6 } $ gawk -F: -f script3.gawk /etc/passwd在gawk脚本中引用变量值时无须使用 $ 符号。 8.1.2.6.在处理数据前运行脚本 gawk允许指定脚本何时运行。 默认情况gawk会从输入中读取一行文本然后对数据执行脚本。有时候需要在处理数据前先运行脚本. BEGIN关键字会强制gawk在读取数据前执行BEGIN关键字之后指定的脚本. $ gawk BEGIN {print Hello World!} Hello World!BEGIN关键字在处理任何数据之前仅应用指定的脚本,在显示过文本后脚本直接结束不等待任何数据。 想使用正常的脚本来处理数据则必须用另一个区域来定义脚本. 在gawk执行了BEGIN脚本后会用第二段脚本来处理文件数据。 两段脚本仍会被视为gawk命令行中的一个文本字符串所以需要加在一个单引号内. $gawk BEGIN {print 请每次输入一个单词!}{print $1} 请每次输入一个单词! apple red apple old new old hello world hello8.1.2.7.在处理数据后运行脚本 和BEGIN关键字类似END关键字允许指定一段脚本gawk会在处理完数据后执行这段脚本 $gawk BEGIN {print 请每次输入一个单词!}{print $1}END {print 输入结束} data3.txt 请每次输入一个单词! apple red apple old new old hello world hello 输入结束特殊变量FS是定义字段分隔符的另一种方法。无须依靠脚本用户通过命令行选项定义字段分隔符. BEGIN { print The latest list of users and shells print UserID \t Shell print ------- \t ------- FS: }{ print $1 \t $7 }END { print This concludes the listing } $ gawk -f script4.gawk /etc/passwd The latest list of users and shells UserID Shell -------- ------- root /bin/bash daemon /usr/sbin/nologin ... sshd /usr/sbin/nologin This concludes the listing更多gawk进阶 8.2.sed编辑器基础命令 选项描述-e commands处理输入时,加入额外的sed命令-f file处理输入时,将file中指定的命令添加到已有命令中-n不产生输出,使用p(print)命令完成输出 8.2.1.更多的替换选项 8.2.1.1.替换标志 替换命令在替换多行中的文本时使用默认情况下它只替换每行中出现的第一处匹配文本。 $ cat data4.txt This is a test of the test script. This is the second test of the test script. $ sed s/test/trial/ data4.txt This is a trial of the test script. This is the second trial of the test script.要想替换每行中所有的匹配文本必须使用替换标志substitution flag。替换标志在替换命令字符串之后设置。 sed s/pattern/replacement/flags file有4种可用的替换标志: 数字指明新文本将替换行中的第几处匹配。g指明新文本将替换行中所有的匹配。p指明打印出替换后的行。w file将替换的结果写入文件。 数字替换标志,替换指定匹配处: $ sed s/test/trial/2 data4.txt This is a test of the trial script. This is the second test of the trial script.g替换标志,替换所有: $ sed s/test/trial/g data4.txt This is a trial of the trial script. This is the second trial of the trial script.p替换标志,打印出包含替换命令中指定匹配模式的文本行。通常和sed的-n选项配合使用. -n选项会抑制sed编辑器的输出替换标志p会输出替换后的行。配合使用只输出被替换命令修改过的行。 $ cat data5.txt This is a test line. This is a different line. $ sed -n s/test/trial/p data5.txt This is a trial line.w替换标志,将替换的结果(仅替换的行)输出保存到指定文件中. sed编辑器的正常输出会被保存在STDOUT中。 $ sed s/test/trial/w test.txt data5.txt This is a trial line. This is a different line. $ cat test.txt This is a trial line.8.2.1.2.替换字符 在字符串中遇到不方便在替换模式中使用的字符。比如正斜线/替换文件中的路径会比较烦琐。 由于正斜线被用作替换命令的分隔符因此它在匹配模式和替换文本中出现时必须使用反斜线来转义。 如果想将/etc/passwd文件中的bash shell替换为C shell: $ sed s/\/bin\/bash/\/bin\/csh/ /etc/passwd为了解决这个问题sed编辑器允许选择其他字符作为替换命令的替代分隔符: $ sed s!/bin/bash!/bin/csh! /etc/passwd以上感叹号!被用作替换命令的分隔符. 8.2.2.使用地址 默认情况下在sed编辑器中使用的命令会应用于所有的文本行。如果只想将命令应用于特定的某一行或某些行可使用行寻址。 sed编辑器中有两种形式的行寻址。 以数字形式表示的行区间。匹配行内文本的模式。 行寻址的格式 [address]command # 将针对特定地址的多个命令分组 address {command1command2command3 }sed编辑器会将指定的各个命令应用于匹配指定地址的文本行。 8.2.2.1.数字形式行寻址 在使用数字形式的行寻址时可以用行号来引用文本流中的特定行。 sed编辑器会将文本流中的第一行编号为1第n行编号为n. 在命令中指定的行地址既可以是单个行号也可以是用起始行号、逗号以及结尾行号指定的行区间。 $可表示最后一行. $ cat data1.txt The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. $ sed 2s/dog/cat/ data1.txt The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy cat. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. $ sed 2,3s/dog/cat/ data1.txt The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy cat. The quick brown fox jumps over the lazy cat. The quick brown fox jumps over the lazy dog. $ sed 2,$s/dog/cat/ data1.txt ## The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy cat. The quick brown fox jumps over the lazy cat. The quick brown fox jumps over the lazy cat.8.2.2.2.使用文本模式过滤 sed编辑器允许指定文本模式来过滤出命令所应用的行. 必须将指定的模式patten放入正斜线内。sed编辑器会将该命令应用于包含匹配模式的行。 sed /pattern/command file$ grep /bin/bash /etc/passwd root:x:0:0:root:/root:/bin/bash christine:x:1001:1001::/home/christine:/bin/bash rich:x:1002:1002::/home/rich:/bin/bash $ sed /rich/s/bash/csh/ /etc/passwd root:x:0:0:root:/root:/bin/bash daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin ... rich:x:1002:1002::/home/rich:/bin/csh在文本模式中引入正则表达式来创建匹配效果更好的模式. 8.2.2.3.命令组 在单行中执行多条命令可以用 {} 组合在一起sed编辑器会执行匹配地址中列出的所有命令. 可以在一组命令前指定行区间. $ sed 2{s/fox/toad/s/dog/cat/} data1.txt The quick brown fox jumps over the lazy dog. The quick brown toad jumps over the lazy cat. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.8.2.3.删除行(d) 文本替换命令并非sed编辑器唯一的命令。如果需要删除文本流中的特定行可以使用删除d命令。 删除命令会删除匹配指定模式的所有行。使用该命令时如果忘记加入寻址模式则流中的所有文本行都会被删除. 同样的,sed编辑器的删除命令也不会修改原始文件. $ cat data1.txt The quick brown fox jumps over the lazy dog The quick brown fox jumps over the lazy dog The quick brown fox jumps over the lazy dog The quick brown fox jumps over the lazy dog $ sed d data1.txt从数据流中删除特定的文本行: 通过行号指定$ cat data6.txt This is line number 1. This is line number 2. This is the 3rd line. This is the 4th line. $ sed 3d data6.txt This is line number 1. This is line number 2. This is the 4th line.通过特定行区间指定:$ sed 2,3d data6.txt This is line number 1. This is the 4th line.特殊的末行字符指定:$ sed 3,$d data6.txt This is line number 1. This is line number 2.模式匹配:$ sed /number 1/d data6.txt This is line number 2. This is the 3rd line. This is the 4th line.使用两个文本模式来删除某个区间内的行: 一个模式会“启用”行删除功能第二个模式会“关闭”行删除功能sed编辑器会删除包含两个指定行与之间的所有行. 只要sed编辑器在数据流中匹配到了开始模式就会启用删除功能.第二个包含开始模式的行也会触发删除命令,未找到结束模式,则剩余的行会被全部删除. $ cat data7.txt This is line number 1. This is line number 2. This is the 3rd line. This is the 4th line. This is line number 1 again; we want to keep it. This is more text we want to keep. Last line in the file; we want to keep it. $ sed /1/,/3/d data7.txt This is the 4th line.8.2.4.插入和附加文本(a\i) sed编辑器也可以向数据流中插入和附加文本行。 插入inserti命令会在指定行前增加一行。附加appenda命令会在指定行后增加一行。 命令不能在单个命令行中使用。必须指定 插入还是附加 到另一行. sed [address]command\ new line file插入与附加 $ echo Test Line 2 | sed i\Test Line 1 Test Line 1 Test Line 2 $ echo Test Line 2 | sed a\Test Line 1 Test Line 2 Test Line 1 $ echo Test Line 2 | sed i\Test Line 1 Test Line 1 Test Line 2向数据流内部插入或附加数据须用地址指定数据出现在什么位置。 只能指定一个行地址。不能用行区间.(只能将文本插入或附加到某一行而不是行区间的前后) $ cat data6.txt This is line number 1. This is line number 2. This is the 3rd line. This is the 4th line. $ sed 3i\This is an inserted line.data6.txt This is line number 1. This is line number 2. This is an inserted line. This is the 3rd line. This is the 4th line. $ $ sed $a\This line was added to the end of the file.data6.txt This is line number 1. This is line number 2. This is the 3rd line. This is the 4th line. This line was added to the end of the file.在数据流的起始位置增加一个新行。只要在第一行之前插入新行。 在数据流的末尾位置增加一个新行。只要在最后一行之后附加新行。 添加多行 要插入或附加多行文本必须在要插入或附加的每行新文本末尾使用反斜线\ $ sed 1i\This is an inserted line.\This is another inserted line.data6.txt This is an inserted line. This is another inserted line. This is line number 1. This is line number 2. This is the 3rd line. This is the 4th line.8.2.5.修改行© 修改c命令允许修改数据流中整行文本的内容。必须在sed命令中单独指定一行. $ sed 2c\This is a changed line of text.data6.txt This is line number 1. This is a changed line of text. This is the 3rd line. This is the 4th line. $ sed /3rd line/c\This is a changed line of text.data6.txt This is line number 1. This is line number 2. This is a changed line of text. This is the 4th line.文本模式修改命令会修改所匹配到的任意文本行. 在修改命令中使用地址区间,会将区间内的所有内容替换为一个文本内容,而不会将每一行替换一次. $ cat data6.txt This is line number 1. This is line number 2. This is the 3rd line. This is the 4th line. $ sed 2,3c\This is a changed line of text.data6.txt This is line number 1. This is a changed line of text. This is the 4th line.8.2.6.转换命令(y) 转换y命令是唯一可以处理单个字符的sed编辑器命令。 sed [address]y/inchars/outchars/ file转换命令会对inchars和outchars的字符进行一对一的映射。 inchars中的第一个字符会被转换为outchars中的第一个字符inchars中的第n字符会被转换成outchars中的第n字符。 如果inchars和outchars的长度不同sed编辑器会产生错误消息。 转换命令是一个全局命令会对文本行中匹配到的所有指定字符进行转换不考虑字符出现的位置,也无法对特定位置字符的转换进行限制: $ cat data9.txt This is line 1. This is line 5. This is line 1 again. This is line 3 again. This is the last file line. $ sed y/123/789/ data9.txt This is line 7. This is line 5. This is line 7 again. This is line 9 again. This is the last file line. $ echo Test #1 of try #1. | sed y/123/678/ Test #6 of try #6.8.2.7.打印 打印数据流中的信息。 打印p命令用于打印文本行。等号命令用于打印行号。列出l命令用于列出行。 打印行§ 和替换命令中的p标志类似打印命令用于打印sed编辑器输出中的一行。 $ echo this is a test | sed p this is a test this is a test常见的用法是打印包含匹配文本模式的行,通过-n抑制其他行输出: $ cat data6.txt This is line number 1. This is line number 2. This is the 3rd line. This is the 4th line. $ sed -n /3rd line/p data6.txt This is the 3rd line.在使用替换或修改命令做出改动之前查看相应的行: $ sed -n /3/{ps/line/test/p} data6.txt This is the 3rd line. This is the 3rd test.打印数据流中的部分行: $ sed -n 2,3p data6.txt This is line number 2. This is the 3rd line.打印行号() 等号命令会打印文本行在数据流中的行号。行号由数据流中的换行符决定。 sed编辑器在实际文本行之前会先打印行号。 $ cat data1.txt The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. $ $ sed data1.txt 1 The quick brown fox jumps over the lazy dog. 2 The quick brown fox jumps over the lazy dog. 3 The quick brown fox jumps over the lazy dog. 4 The quick brown fox jumps over the lazy dog.让sed编辑器只显示包含匹配文本模式的文本行的行号和内容: $ cat data7.txt This is line number 1. This is line number 2. This is the 3rd line. This is the 4th line. This is line number 1 again; we want to keep it. This is more text we want to keep. Last line in the file; we want to keep it. $ sed -n /text/{p} data7.txt 6 This is more text we want to keep.列出行(l) 列出命令可以打印数据流中的文本和不可打印字符。 在显示不可打印字符的时候可以使用反斜杠加八进制值或使用标准的C语言命名规范比如\t用于代表制表符. $ cat data10.txt This line contains tabs. This line does contain tabs. $ sed -n l data10.txt This\tline\tcontains\ttabs.$ This line does contain tabs.$8.2.8.处理文件 写入文件(w) 命令格式: sed [address]w filename filefilename可以使用相对路径或绝对路径.用户必须有文件的写权限。地址可以是任意类型的寻址方式. $ sed 1,2w test.txt data6.txt This is line number 1. This is line number 2. This is the 3rd line. This is the 4th line. $ cat test.txt This is line number 1. This is line number 2.可以使用-n选项抑制输出. 根据一些文本值从主文件比如下面的邮件列表中创建一份数据文件使用写入命令会非常方便: $ cat data12.txt Blum, R Browncoat McGuiness, A Alliance Bresnahan, C Browncoat Harken, C Alliance $ sed -n /Browncoat/w Browncoats.txt data12.txt $ cat Browncoats.txt Blum, R Browncoat Bresnahan, C Browncoat读取数据® 取r命令允许将一条独立文件中的数据插入数据流。将文件内容插入指定地址之后. 无法使用地址区间只能指定单个行号或文本模式地址。 命令格式: sed [address]r filename file$ cat data13.txt This is an added line. This is a second added line. $ sed 3r data13.txt data6.txt This is line number 1. This is line number 2. This is the 3rd line. This is an added line. This is a second added line. This is the 4th line. $ sed /number 2/r data13.txt data6.txt This is line number 1. This is line number 2. This is an added line. This is a second added line. This is the 3rd line. This is the 4th line. $ sed $r data13.txt data6.txt This is line number 1. This is line number 2. This is the 3rd line. This is the 4th line. This is an added line. This is a second added line.读取命令和删除命令配合使用利用一个文件中的数据来替换另一个文件中的占位文本。 假如你保存在文本文件中的套用信件如下 $ cat notice.std Would the following people: LIST please report to the ships captain.在占位文本后插入名单只需使用读取命令即可。但这样的话占位文本仍然会留在输出中。为此可以用删除命令删除占位文本 $ sed /LIST/{r data12.txtd} notice.std Would the following people: Blum, R Browncoat McGuiness, A Alliance Bresnahan, C Browncoat Harken, C Alliance please report to the ships captain.文件夹下文件 -s选项可以告知sed将目录内的各个文件作为单独的流 $ sed -sn 1s!/bin/sh!/bin/bash! OldScripts/*.sh将 OldScripts文件夹下的.sh文件第一行内的/bin/sh的替换为/bin/bash.
http://www.dnsts.com.cn/news/248463.html

相关文章:

  • 图片上加语音 网站开发万网网站建设选哪个好
  • seo营销型网站济南网站建设团队
  • 网站开发中遇到哪些问题下载应用的app
  • 做模拟人生比较有名的网站学校网站需求
  • 做网站得多钱北京推广网站
  • 重庆网站制作设计263邮箱个人登录入口
  • 加强财政门户网站建设工作变化型网页网站有哪些
  • 猜艺士科技网站建设杭州网站的建设
  • 电商网站建设内容电商网站建设开发
  • 嘉兴公司的网站设计开发网站和电脑软件的区别
  • 清城区做模板网站建设品牌网站设计视频教程
  • 企业网站建设 管理 维护手机便宜电商网站建设
  • 北京哪家网站建设公司好网页设计 教程网站
  • 做网站费用 会计分录绿色大气5.7织梦网站模版
  • 电子商务网站建设与管理课程评价项目网发布信息平台
  • 做网站开发公司国内著名展馆设计公司报价
  • 去哪里找做网站 的客户公司做一个网站内容如何设计
  • 网站虚拟主机公司html用表格来做网站布局
  • 汇米网站建设上海进一步优化
  • 怎样才能有自己的网站怎么创建网页链接
  • 做网站需要多少钱 爱问知识人秦皇岛黄金海岸
  • 如何免费推广网站深圳工程建设服务网
  • 云南昌旅游的网站建设中通建设计院网站
  • 服务推广网站h5制作平台排行榜
  • 学网站开发需要学那些自有服务器怎么做网站备案
  • 狼窝网站更新升级通知沈阳市网站建设
  • 成都网站排名公司做网站一天忙吗
  • 电子商务网站建设特点网页制作中的常见问题
  • 网站建设微商城wordpress模板左上角的logo换成自己的
  • 化纤公司网站建设国家企业信息认证系统