vim grep sed awk对大小写不敏感
环境
[root@osker ~]# cat /etc/redhat-release
CentOS Linux release 7.6. (Core)
[root@osker ~]# uname -r
3.10.-.el7.x86_64
1 [root@osker ~]# cat 3.txt
2 Mike Harrington:[510] 548-1278:250:100:175
3 Christian Dobbins:[408] 538-2358:155:90:201
4 tom
5 Chet Main:[510] 548-5258:50:95:135
6 Tom Savage:[408] 926-3456:250:168:
文档中有tom和Tom两个关键词
vim
:set ic (ignorecase 的缩写)忽略大小写
:set noic (noignorecase 的缩写)不忽略大小写
grep
查询man帮助可以找到,使用-i参数可以忽略大小。
-i, --ignore-case:Ignore case distinctions in both the PATTERN and the input files. (-i is specified by POSIX.)
[root@osker ~]# grep -i 'tom' .txt
tom
Tom Savage:[] -:::
sed
[root@osker ~]# sed -n '/tom/Ip' .txt
tom
Tom Savage:[] -:::
[root@osker ~]# sed -n '/tom/ip' .txt
p
可以看出在/后加入 I 可以忽略大小写过滤,使用i会出错。
[root@osker ~]# sed -n 's#tom#qiu#gp' .txt
qiu
[root@osker ~]# sed -n 's#tom#qiu#gpi' .txt
qiu
qiu Savage:[] -:::
[root@osker ~]# sed -n 's#tom#qiu#gpI' .txt
qiu
qiu Savage:[] -:::
在使用替换功能时候可以时用i或者I,对需要替换的词忽略大小写。
在GNU找了好久,找到这么一段话:
i I :The I modifier to regular-expression matching is a GNU extension which makes sed match regexp in a case-insensitive manner.
引用链接:
https://www.gnu.org/software/sed/manual/html_node/The-_0022s_0022-Command.html#The-_0022s_0022-Command
awk
[root@osker ~]# awk '/tom/' IGNORECASE= .txt
tom
Tom Savage:[] -:::
查看man帮助可以查询到,awk内置了一个IGNORECASE变量,专门用于处理大小写的忽略。当IGNORECASE的值为真时,则进行忽略大写的匹配。
IGNORECASE:
Controls the case-sensitivity of all regular expression and string operations. If IGNORECASE has a non-zero value, then string comparisons and pattern matching in rules, field splitting with FS and FPAT, record separating with RS, regular expression matching with ~ and !~, and the gensub(), gsub(), index(), match(), patsplit(), split(), and sub() built-in functions all ignore case when doing regular expression operations. NOTE: Array subscripting is not affected. However, the asort() and asorti() functions are affected.
Thus, if IGNORECASE is not equal to zero, /aB/ matches all of the strings "ab", "aB", "Ab", and "AB". As with all AWK variables, the initial value of IGNORECASE is zero, so all regular expression and string operations are normally case-sensitive.
vim grep sed awk对大小写不敏感的更多相关文章
- Linux三剑客grep/sed/awk
grep/sed/awk被称为linux的“三剑客” grep更适合单纯的查找或匹配文本: sed更适合编辑匹配到的文本: awk更适合格式化文本,对文本进行较复杂各式处理: Grep --color ...
- linux三剑客grep|sed|awk实践
最好先学习正则表达式的基本用法,以及正则表达式BREs,EREs,PREs的区别 此坑待填 grep sed awk
- 【shell脚本练习】grep sed awk
下面是简单学习之后做得练习题,如果有不对的或者说解题思路不好的,请交流啊. Grep 练习 文件名grepfile Steve Blenheim:238-923-7366:95 Latham Lane ...
- Shell学习:grep, sed, awk命令的练习题
http://www.cnblogs.com/chengmo/archive/2013/01/17/2865479.html 文件:datafileSteve Blenheim:238-923-736 ...
- 【Linux】 字符串和文本处理工具 grep & sed & awk
Linux字符串&文本处理工具 因为用linux的时候主要用到的还是字符交互界面,所以对字符串的处理变得十分重要.这篇介绍三个常用的字符串处理工具,包括grep,sed和awk ■ grep ...
- [svc]linux正则实战(grep/sed/awk)
企业实战: 过滤ip 过滤出第二行的 192.168.2.11. eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 ine ...
- Linux基础命令-Nginx-正则表达式( grep sed awk )-Shell Script--etc
Linux基础使用 学习内容博客 内存 查看swap分区信息 > swapon -s 添加swap分区 > mkswap /dev/sdb2 > 激活 swapon -a /dev/ ...
- linux grep,sed,awk和diff的使用
1:grep//显示行 # grep 'main' /home/myhome/a.c//将a.c含有main的行显示出来 # grep -v 'main' /home/myhome/a.c //显示除 ...
- grep sed awk 3个Linux中对文件内容操作的命令
在学习Linux命令中,发现3个有关于文件内容操作的命令grep,sed和awk,在这里简单汇总这3个命令主要作用,在实际中找到最合适的情景应用,详细用法可以参考其他文章. 1.grep命令 主要作用 ...
随机推荐
- swoole 异步非堵塞 server/端 client/端 代码,已经测试完毕。贴代码
服务器环境 centos7.0 swoole4.3 php7.2 pcre4.8 nginx1.8 php-fpm server.php <?php class Server { pr ...
- 【colab pytorch】使用tensorboard可视化
import datetime import torch import torch.nn as nn import torch.nn.functional as F import torch.opti ...
- 2019-2020-2 20174318张致豪《网络对抗技术》Exp1 PC平台逆向破解
Exp1_PC平台逆向破解 前期准备 一.逆向及Bof基础实践说明 1.1 实践目标 本次实践的对象是一个名为pwn1的linux可执行文件. 该程序正常执行流程是:main调用foo函数,foo函数 ...
- Mathtype快捷键&小技巧
Mathtype使用方便,能插入到Office等编辑器中,Latex公式在某些地方更加通用,如网页和书籍. 1. Mathtype简介 数学公式编辑器(MathType)是一款专业的数学公式编辑工具, ...
- springBoot启动后 http://localhost:8080 地址无法访问
http://localhpost:8080/hello 代码结构: 代码内容: @RestController public class HelloWordRestImpl implements H ...
- IOptions、IOptionsMonitor以及IOptionsSnapshot
背景 ASP.NET Core引入了Options模式,使用类来表示相关的设置组.简单的来说,就是用强类型的类来表达配置项,这带来了很多好处.初学者会发现这个框架有3个主要的面向消费者的接口:IOpt ...
- Error while importing sbt project:--创建sbt项目导入文件出错
错误截图如下: Error while importing sbt project: List([info] Loading global plugins from C:\Users\RYJ\.sbt ...
- CentOS7设置环境变量
目录 一.环境变量的概念 1.环境变量的含义 2.环境变量的分类 3.Linux环境变量 二.常用的环境变量 1.查看环境变量 2.常用的环境变量 三.设置环境量 1.系统环境变量 2.用户环境变量 ...
- Red Team 工具集之网络钓鱼和水坑攻击
来自:信安之路(微信号:xazlsec),作者:myh0st 参考项目:https://github.com/infosecn1nja/Red-Teaming-Toolkit 上图是一个 Red Te ...
- Oracle 中文日期转换
中文日期转换 select to_char(to_date('07-5月-17'),'yyyy-MM-dd HH24:mi:ss') from dual