由于目前测试的BIOS有一个option 发生了改变,因此我们需要在之前写好的脚本上进行修改,将旧的option 改为新的选项,因此在此处用到了批量修改文件中的内容;

1. perl 命令替换:

perl -i -e "s/old/new/g" the path of the file

下面,就将test1 text2,中的cat 都换成了dog,汪汪~~

[root@ tmp]# touch test1.txt
[root@ tmp]# vim test1.txt
[root@ tmp]# cat test1.txt
cat cat cat
i like linux
i like windows too
i like watching TV
I like chenqingling [root@ tmp]# cp test1.txt text2.txt
[root@ tmp]# cp test1.txt text3.txt
[root@ tmp]# cp test1.txt text4.txt
[root@ tmp]# perl -p -i -e "s/cat/dog/g" test1.txt text2.txt
[root@ tmp]# cat test1.txt
dog dog dog
i like linux
i like windows too
i like watching TV
I like chenqingling [root@ tmp]# cat text2.txt
dog dog dog
i like linux
i like windows too
i like watching TV
I like chenqingling [root@ tmp]# cat text3.txt
cat cat cat
i like linux
i like windows too
i like watching TV
I like chenqingling

2.运用sed 命令批量修改文件内容:

sed -i "s/old/new/g" the path of the files

修改text2,text3,中的linux ,修改为Unix

[root@ tmp]# sed -i "s/linux/Unix/g" text2.txt text3.txt
[root@ tmp]# cat text2.txt
dog dog dog
i like Unix
i like windows too
i like watching TV
I like chenqingling [root@ tmp]# cat text3.txt
cat cat cat
i like Unix
i like windows too
i like watching TV
I like chenqingling [root@ tmp]# cat test1.txt
dog dog dog
i like linux
i like windows too
i like watching TV
I like chenqingling

 3.补充点:将old 全部换成 new 

sed -i “s/old/new/g” `grep old -rl /path`    #当前路径表示:./

[root@ lu]# sed -i "s/TV/xiaozhan/g" `grep TV -rl ./` #注意这里的`` 不是单引号!!
[root@ lu]# cat text2.txt
dog dog dog
i like Unix
i like windows too
i like watching xiaozhan
I like chenqingling [root@ lu]# cat text3.txt
cat cat cat
i like Unix
i like windows too
i like watching xiaozhan
I like chenqingling [root@ lu]# cat text4.txt
cat cat cat
i like linux
i like windows too
i like watching xiaozhan
I like chenqingling

linux --批量修改文件内容的更多相关文章

  1. linux批量替换文件内容3种方法(perl,sed,shell)

    方法1:perl   这两天在构建一个应用的使用用到了maven,由于project很大,足足有700多个 pom.xml文件,更郁闷的是在很多pom.xml文件里都单独指定了资源库的url,我需要把 ...

  2. Linux批量替换文件内容

    问题描述:现在需要将rack1目录下*.send文件中的"-ip="替换成“-localIp=10.0.0.1/n-ip=” 刚才那个批量文本内容替换,只能替换内存中的内容,并不会 ...

  3. sed命令——批量修改文件内容

    批量替换单个文件内容 命令格式:sed -i 's/旧内容/新内容/g' 文件路径 sed -i 's/oldString/newString/g' file 例如:我想替换cwx.txt文件中的 j ...

  4. linux 批量替换文件内容及查找某目录下所有包含某字符串的文件

    转载请注明来源:https://www.cnblogs.com/hookjc/ 1. sed C代码   grep -rl matchstring somedir/ | xargs sed -i 's ...

  5. Python3 写的远程批量修改文件内容的脚本

    一.说明: 1.利用Python的paramiko模块,调用远程的shell命令去修改相应文件. 2.有一个专用配置文件,列出服务器清单. 3.Python循环读取配置文件的服务器IP去连接它,并执行 ...

  6. python批量修改文件内容及文件编码方式的处理

    最近公司在做tfs迁移,后面要用新的ip地址去访问tfs 拉取代码  ,所以原来发布脚本中.bat类型的脚本中的的ip地址需要更换 简单说下我们发布脚本层级目录 :每个服务站点下都会有一个发布脚本 . ...

  7. linux VI模式下批量修改文件内容

    1.         :s/vivian/sky/ 替换当前行第一个 vivian 为 sky            :s/vivian/sky/g 替换当前行所有 vivian 为 sky 2.   ...

  8. 使用sed,grep 批量修改文件内容

    使用sed命令可以进行字符串的批量替换操作,以节省大量的时间及人力: 使用的格式如下: sed -i "s/oldstring/newstring/g" `grep oldstri ...

  9. linux批量查找文件内容

    find ./ -name "*.php" | xargs grep '要查找的内容' 如果需要查找的内容包含特殊符号,比如$等等,grep要加参数 find ./ -name & ...

随机推荐

  1. 4.JS跳转路由/刷新/返回页面

    1.JS跳转路由(需要拿到父组件的history) clickHandle(){ let history = this.props.history; history.push( '/home') } ...

  2. 二、Go语言开发环境安装与编写第一个Hello World

    本系列文章均为学习过程中记录的笔记,欢迎和我一起来学习Go语言. 全文使用环境如下: Go语言版本:1.13 操作系统:deepin 使用工具:Goland开发工具 Go语言追溯历史 Go语言2009 ...

  3. SpringBoot应用操作Rabbitmq

    记录RabbitMQ的简单应用 1.springboot项目中引入maven包,也是springboot官方的插件 <dependency> <groupId>org.spri ...

  4. 1月份中国综合PMI指数为53.2% 企业生产经营活动总体增速加快

    中新社北京1月31日电 (记者 王恩博)中国国家统计局31日发布数据显示,2019年1月份,中国综合PMI产出指数为53.2%,比上月上升0.6个百分点,表明中国企业生产经营活动总体增速加快. 其中, ...

  5. shell基础知识DAY2

    1.管道符(|):把一个命令的输出,把输出的内容传递给管道符后面命令的输入.如:ls -l | grep "^[^d]".2.jobs作业控制,后台运行bg PID,前台运行fg ...

  6. 集合框架-day10

    day10-集合框架-对象数组的概述与引用 1 集合框架的简单介绍: A:集合的由来 数组长度是固定,当添加的元素超过了数组的长度时需要对数组重新定义,太麻烦,java内部给我们提供了集合类,能存储任 ...

  7. SpringMVC Root WebApplicationContext启动流程

    传统的SpringMVC项目中,需要在web.xml中配置Contextlistener.ContextLoaderListener是负责引导启动和关闭Spring的Root上下文的监听器.主要将处理 ...

  8. Android FrameWork学习(二)Android系统源码调试

    通过上一篇 Android FrameWork学习(一)Android 7.0系统源码下载\编译 我们了解了如何进行系统源码的下载和编译工作. 为了更进一步地学习跟研究 Android 系统源码,今天 ...

  9. Markdown中希腊字母与代码对应表

    字母 代码 α\alphaα $\alpha$ β\betaβ $\beta$ γ\gammaγ $\gamma$ Γ\GammaΓ $\Gamma$ δ\deltaδ $\delta$ Δ\Delt ...

  10. 字符串后面空字符的问题(char*与string的转换)

    今天AC了不少题,困扰已久的Time limit error 也解决了,记住下次用STL容器的时候一定要清空容器. 其次是字符数组与字符串的浅谈. 字符数组是以'\0'结尾的,所以在字符数组赋值给字符 ...