Sed 静默替换文件内容 以及 awk 的简单使用
1. Sed的help
鸟哥说的 学东西 先看 help 先看man 再google 不好翻墙再百度..
Usage: sed [OPTION]... {script-only-if-no-other-script} [input-file]...
-n, --quiet, --silent
suppress automatic printing of pattern space
-e script, --expression=script
add the script to the commands to be executed
-f script-file, --file=script-file
add the contents of script-file to the commands to be executed
--follow-symlinks
follow symlinks when processing in place
-i[SUFFIX], --in-place[=SUFFIX]
edit files in place (makes backup if SUFFIX supplied)
-c, --copy
use copy instead of rename when shuffling files in -i mode
-b, --binary
does nothing; for compatibility with WIN32/CYGWIN/MSDOS/EMX (
open files in binary mode (CR+LFs are not treated specially))
-l N, --line-length=N
specify the desired line-wrap length for the `l' command
--posix
disable all GNU extensions.
-r, --regexp-extended
use extended regular expressions in the script.
-s, --separate
consider files as separate rather than as a single continuous
long stream.
-u, --unbuffered
load minimal amounts of data from the input files and flush
the output buffers more often
-z, --null-data
separate lines by NUL characters
--help
display this help and exit
--version
output version information and exit
2. 感觉用的最多的就是 sed -i 静默本地替换文件内容.
简单的练习
vim zhaobsh.txt
zhaobsh is cainiao
zhaobsh is cainiaocainiao
保存之后进行替换
1. 每行增加一个 Yes
sed -i 's/^/Yes /' zhaobsh.txt

2. 没个末尾增加一个 Enough
sed -i 's/$/ Enough/' zhaobsh.txt
效果

3. 将 cainiao 替换才caibi
sed -i 's/cainiao/caibi/' zhaobsh.txt

4. 替换所有的菜鸟的命令
sed -i 's/cainiao/caibi/g' zhaobsh.txt
5. 删除 包含某字符的一整行
sed -i '/Enough/d' zhaobsh.txt
备注 这里会删掉 Enough 所在的整行信息.
简单的学习一下 后续工作中 会越来越多的用到.
其他的命令暂时还没学. 用到了 再继续整理.
备注 一些正则表达式的定义相关
^ 表示一行的开头。如:/^#/ 以#开头的匹配。
$ 表示一行的结尾。如:/}$/ 以}结尾的匹配。
\< 表示词首。 如 \<abc 表示以 abc 为首的詞。
\> 表示词尾。 如 abc\> 表示以 abc 結尾的詞。
. 表示任何单个字符。
* 表示某个字符出现了0次或多次。
[ ] 字符集合。 如:[abc]表示匹配a或b或c,还有[a-zA-Z]表示匹配所有的26个字符。如果其中有^表示反,如[^a]表示非a的字符
awk的简单使用 显示 文件的一部分内容
之前删除所有 error的机器 的方法就是使用 awk 来的
1. 创建测试文件
netstat -ano >awk.txt
显示所有 第八项目为"/run/systemd/journal/stdout" 的内容
awk '$8=="/run/systemd/journal/stdout" {print $0}' awk.txt
Sed 静默替换文件内容 以及 awk 的简单使用的更多相关文章
- linux下sed批量替换文件内容
在linux超级终端下编辑文档是件比较麻烦的事情,下面简单介绍一下如何在linux下批量替换文件内容 linuxsed 批量替换多个文件中的字符串 格式: sed -i "s/查找字段/替换 ...
- sed命令替换文件内容
reference: https://www.cnblogs.com/starof/p/4181985.html 抓取目录名并修改 ls | grep "XXX" > 1.t ...
- linux批量替换文件内容3种方法(perl,sed,shell)
方法1:perl 这两天在构建一个应用的使用用到了maven,由于project很大,足足有700多个 pom.xml文件,更郁闷的是在很多pom.xml文件里都单独指定了资源库的url,我需要把 ...
- sed命令及替换文件内容
一.sed (三剑客老二) 1.sed 替换文件内容 sed s###g file 前面两个#中的是原内容,后两个#中的是替换的内容 例:将a.txt文件中的linux替换成java 但是,此时 ...
- perl命令批量替换文件内容
转自:http://www.jbxue.com/article/12638.html 使用perl命令批量替换文件内容. 对linux下的文件内容进行替换,有时不用编写perl脚本,用perl命令就可 ...
- [转帖]Linux下批量替换文件内容方法
Linux下批量替换文件内容方法 https://www.cnblogs.com/fjping0606/p/4428850.html 刚才用到的命令 原作者写的挺好的记录一下 以后 用. 1:查找fi ...
- Linux批量替换文件内容
问题描述:现在需要将rack1目录下*.send文件中的"-ip="替换成“-localIp=10.0.0.1/n-ip=” 刚才那个批量文本内容替换,只能替换内存中的内容,并不会 ...
- Linux替换文件内容sed命令
sed -e 4a\newline testfile //在第四行后添加一行,并将结果输出到标准输出.-e,以指定脚本处理文本文件:a,新增. nl /etc/passwd | sed '2,5d' ...
- sed命令实现文件内容替换总结案例
sed -i "s@AAAAA@BBBBB@g" /home/local/payment-biz-service/env/test.txt sed -i "s#htxk. ...
随机推荐
- OpenCV——ORB特征检测与匹配
原文链接:https://mp.weixin.qq.com/s/S4b1OGjRWX1kktefyHAo8A #include <opencv2/opencv.hpp> #include ...
- Python2.7-fractions
fractions 模块,提供分数格式存储数据,没多大用处,除了模块里的最大公约数函数 gcd(a,b) 模块类和方法: fractions.Fraction(numerator=0, denomin ...
- css 字体、文本、padding的样式
一.字体的样式: 1)字体倾斜:font-style:italic 2)字体大小:font-size 一般为偶数. 3)行高:line-height 当行高为奇数的时候,是文字上面比文字下面的少一 ...
- JAVA框架:hibernate(四)
一.绑定本地session 原理:之前connection实现事务一个道理,2种方法:1.变量下传.2.因为servlet是单线程,和本地当前线程绑定. 配置: 1)配置核心配置文件hibernate ...
- 浅拷贝与深拷贝的实现方式、区别;deepcopy如果你来设计,如何实现(一)
浅拷贝与深拷贝的实现方式.区别:deepcopy如果你来设计,如何实现: copy浅拷贝:没有拷贝子对象,所以原始数据改变,子对象改变 deepcopy深拷贝:包含对象里面的子对象的拷贝,所以原始对象 ...
- visual studio 插件
一:VS10x Code Map(打开后台cs文件,插件列出了所有的字段.方法,方便当代码行多的时候查找,提升工作效率) 1:下载 https://marketplace.visualstudio.c ...
- ROS launch 文件的编写
ROS提供了一个同时启动节点管理器(master)和多个节点的途径,即使用启动文件(launch file).事实上,在ROS功能包中,启动文件的使用是非常普遍的.任何包含两个或两个以上节点的系统都可 ...
- jQuery的extend和fn.extend理解
参考网址:http://www.cnblogs.com/yuanyuan/archive/2011/02/23/1963287.html http://www.cnblogs.com/xuxiuyu/ ...
- php判断一个数组是否为另一个数组子集的方法
原文地址http://www.jbxue.com/article/14703.html // 快速的判断$a数组是否是$b数组的子集 $a = array(135,138); $b = array ...
- odoo tree视图 当页不弹窗显示方法
<xpath expr="//tree" position="attributes"> <attribute name='editable'& ...