当前位置:网站首页>perl 命令批量替换文件中的一些内容
perl 命令批量替换文件中的一些内容
2022-07-17 18:13:00 【学亮编程手记】
perl 命令可以批量替换文件中的一些内容,操作起来非常高效。下面举几个例子:
perl -pi -e "s/aaa/bbb/gi" test.txt
- 上面的命令把test.txt文件中的字符aaa替换成bbb
perl -pi.bak -e "s/aaa/bbb/gi" test.txt
- 上面的命令把test.txt文件中的字符aaa替换成bbb,并生成一个test.txt.bak的备份文件
find ./ -name "*.txt" | xargs perl -pi.bak -e "s/aaa/bbb/gi"
- 上面的命令把当前目录下所有的.txt文件中的字符aaa替换成bbb,并生成相应的.bak的备份文件
注意:如果是报错can‘t do inpalce without backup ,请执行第二种方案,针对window进行验证过。
-p 告诉Perl对后面添加的文件名参数进行遍历,大致和sed中的这段代码效果类似
-i 大致是用来读取文件时进行备份操作。
-e 告诉Perl后面跟上perl语句
-p和-i可以合在一起-pi,-p -e也可以何在一起,但是-i,-e不能合在一起写-ie。
边栏推荐
- R language -- principle of Cox model calibration curve (I) data source
- 光大期货网上开户安全吗?有没有开户指引?
- LeetCode 0118. Yanghui triangle
- When will the deflationary market reverse? How should we operate? 2020-03-13
- 如何优雅的升级 Flink Job?
- 面试难题:分布式 Session 实现难点,这篇就够!
- MOF customized materials | bimetallic CuNi MOF nano materials | core-shell structure [email protected] Nanocomposites | zif-8/ poly
- Interview difficulties: difficulties in implementing distributed session, this is enough!
- [try to hack] ARP and ARP deception
- S32K148_ Can drive (bare metal development)
猜你喜欢

【刷题记录】13. 罗马数字转整数

模块7(王者荣耀商城异地多活架构设计)

JVM self study summary

C语言进阶——自定义类型:结构体 枚举 联合

Advanced C language -- character function and string function

VMware导入ova/ovf虚拟机文件

Supported metal organic framework zif-8 / graphene oxide hydrogen storage material | titanium dioxide /zif-8 composite | silicon dioxide @zif8 nano material

【Pygame 学习笔记】6.Cursor 鼠标光标

国产API工具哪家强?原来是它…

2022 global developer salary exposure: China ranks 19th, with an average annual salary of $23790
随机推荐
Advanced C language -- custom type: structure enumeration Union
Reg of sequential logic and combinatorial logic
R语言--Cox模型校准曲线原理(一)数据来源
【Pygame 学习笔记】5.rect对象的碰撞检测
松下A6伺服驱动器外部绝对值光栅尺全闭环参数设置
運維小白成長記—架構第6周
Minimum exchange times
最懂你的服装设计师是AI?让用户 “凭心意” 生成数字服装#Adidas OZWORLD
How to add a thread in MFC
协同工具协同办公的管理具有哪些痛点
Interview difficulties: difficulties in implementing distributed session, this is enough!
Atmospheric non isohalo effect
Attachment handling of SAP Fiori
实现自动记录日志
The combination of fastadmin with and filed causes field failure
【刷题记录】13. 罗马数字转整数
Attachment handling of SAP Fiori
Amino metal organic framework material Fe MOF, fe-mil-88nh2 | Zr based metal organic framework catalyst (pt-uio-66) | Qiyue biology
Brief analysis of circuit fault
Growth of operation and maintenance Xiaobai - week 6 of Architecture