linux --批量修改文件内容
由于目前测试的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 --批量修改文件内容的更多相关文章
- linux批量替换文件内容3种方法(perl,sed,shell)
方法1:perl 这两天在构建一个应用的使用用到了maven,由于project很大,足足有700多个 pom.xml文件,更郁闷的是在很多pom.xml文件里都单独指定了资源库的url,我需要把 ...
- Linux批量替换文件内容
问题描述:现在需要将rack1目录下*.send文件中的"-ip="替换成“-localIp=10.0.0.1/n-ip=” 刚才那个批量文本内容替换,只能替换内存中的内容,并不会 ...
- sed命令——批量修改文件内容
批量替换单个文件内容 命令格式:sed -i 's/旧内容/新内容/g' 文件路径 sed -i 's/oldString/newString/g' file 例如:我想替换cwx.txt文件中的 j ...
- linux 批量替换文件内容及查找某目录下所有包含某字符串的文件
转载请注明来源:https://www.cnblogs.com/hookjc/ 1. sed C代码 grep -rl matchstring somedir/ | xargs sed -i 's ...
- Python3 写的远程批量修改文件内容的脚本
一.说明: 1.利用Python的paramiko模块,调用远程的shell命令去修改相应文件. 2.有一个专用配置文件,列出服务器清单. 3.Python循环读取配置文件的服务器IP去连接它,并执行 ...
- python批量修改文件内容及文件编码方式的处理
最近公司在做tfs迁移,后面要用新的ip地址去访问tfs 拉取代码 ,所以原来发布脚本中.bat类型的脚本中的的ip地址需要更换 简单说下我们发布脚本层级目录 :每个服务站点下都会有一个发布脚本 . ...
- linux VI模式下批量修改文件内容
1. :s/vivian/sky/ 替换当前行第一个 vivian 为 sky :s/vivian/sky/g 替换当前行所有 vivian 为 sky 2. ...
- 使用sed,grep 批量修改文件内容
使用sed命令可以进行字符串的批量替换操作,以节省大量的时间及人力: 使用的格式如下: sed -i "s/oldstring/newstring/g" `grep oldstri ...
- linux批量查找文件内容
find ./ -name "*.php" | xargs grep '要查找的内容' 如果需要查找的内容包含特殊符号,比如$等等,grep要加参数 find ./ -name & ...
随机推荐
- JACTF Web部分
掘安团队的题目 平台已不运营 Web签到 发现请求URL为flag.php,但是会跳转到404.php页面,抓包发现有302重定向,查看响应包,flag经过base64编码,解码即可 Tips: 重定 ...
- 【原创】Linux RCU原理剖析(二)-渐入佳境
背景 Read the fucking source code! --By 鲁迅 A picture is worth a thousand words. --By 高尔基 说明: Kernel版本: ...
- ntp和chrony
目录 chrony 简介 ntp pool ntp 配置文件 chrony 配置文件 chronyc 命令行工具 修改时区 chrony 简介 chrony 是 RedHat 开发的,它是网络时间协议 ...
- 理解java容器底层原理--手动实现ArrayList
为了照顾初学者,我分几分版本发出来 版本一:基础版本 实现对象创建.元素添加.重新toString() 方法 package com.xzlf.collection; /** * 自定义一个Array ...
- 2019-2020-1 20199326《Linux内核原理与分析》第三周作业
第三周学习内容 庖丁解牛Linux内核分析第二章:操作系统是如何工作的 Linux内核分析实验二 学到的一些知识 计算机的三大法宝:存储程序计算机,函数调用堆栈,中断 堆栈是C语言程序运行时必须使用的 ...
- 探索ORACLE之ASM概念(完整版)
探索ORACLE之ASM概念(完整版) 本文出自https://www.jb51.net/article/43527.htm ASM是Oracle 10g R2中为了简化Oracle数据库的管理而推出 ...
- mac OS 搭建PHP项目开发环境
系统 macOS Mojave 版本10.14.6 mac OS 自带Apache和PHP 非常便利 sudo apachectl -v //查看apache版本 php -v //查看php版本 启 ...
- windows服务程序的编写
服务编写https://blog.csdn.net/lanuage/article/details/77937407 #include <windows.h> #include <s ...
- angularJS中$http.get( ).success( )报错原因及解决方案
一.问题描述: 电脑安装的angular1.6.7版本,项目中使用了$http.get( ).success( ),控制台报错: $http.get(...).success is not a fun ...
- JAVA_WEB--jsp语法
JSP声明 一个声明语句可以声明一个或多个变量.方法,供后面的Java代码使用.在JSP文件中,必须先声明这些变量和方法然后才能使用它们. JSP声明的语法格式: <%! declaration ...