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. ...
随机推荐
- oracle 查看用户所在的表空间
查看当前用户的缺省表空间 SQL>select username,default_tablespace from user_users; 查看当前用户的角色 SQL>select * fr ...
- windows/Linux动态加载链接库问题
windows: LoadLibraryA 指定的可执行模块映射到调用进程的地址空间并返回该 DLL 的句柄 HMODULE LoadLibraryA( LPCTSTR lpLibFileName// ...
- day70
昨日回顾:1 虚拟环境 -1 pycharm里创建 -2 用命令串讲2 视图层: 1 Request对象---GET,POST,method,body,FILES,META,path(只是路径),ge ...
- 微信小程序开发 [07] 写在后面的话
写在后面的话基本算是吐槽了,在学完小程序的课程之后,我用博客园的api,写了个闪存的小程序,本来兴致勃勃甚至这篇是准备写"我的第一个小程序发布啦",然而并没有. 不是说我偷懒了没写 ...
- STM32驱动ILI9341控制器控制TFTLCD显示
STM32驱动ILI9341控制器控制TFTLCD显示 一.用STM32控制TFTLCD显示的编程方法,在编程驱动TFTLCD液晶显示器之前,我们先熟悉以下概念: 1.色彩深度,这是一个与TFTLCD ...
- 添加默认的过滤条件xml
<search string="Search Sales Origin"> <field name="name"/> <field ...
- Windows Server2003 IIS服务器安全配置整理
一.系统的安装 1.按照Windows2003安装光盘的提示安装,默认情况下2003没有把IIS6.0安装在系统里面.2.IIS6.0的安装 开始菜单—>控制面板—>添加或删除程序—& ...
- 20155318 《网络攻防》Exp5 MSF基础应用
20155318 <网络攻防>Exp5 MSF基础应用 基础问题 用自己的话解释什么是exploit,payload,encode? exploit就相当于是载具,将真正要负责攻击的代码传 ...
- 20155327 实验四 Android程序设计
20155327 实验四 Android程序设计 任务一: 完成Hello World, 要求修改res目录中的内容,Hello World后要显示自己的学号 步骤: 将布局文件activity_ma ...
- 将Centos 的默认yum源改为阿里云的yum源后出现的问题
阿里各版本yum源如下: Centos5:http://mirrors.aliyun.com/repo/Centos-5.repo Centos6:http://mirrors.aliyun.com/ ...