环境

 [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对大小写不敏感的更多相关文章

  1. Linux三剑客grep/sed/awk

    grep/sed/awk被称为linux的“三剑客” grep更适合单纯的查找或匹配文本: sed更适合编辑匹配到的文本: awk更适合格式化文本,对文本进行较复杂各式处理: Grep --color ...

  2. linux三剑客grep|sed|awk实践

    最好先学习正则表达式的基本用法,以及正则表达式BREs,EREs,PREs的区别 此坑待填 grep sed awk

  3. 【shell脚本练习】grep sed awk

    下面是简单学习之后做得练习题,如果有不对的或者说解题思路不好的,请交流啊. Grep 练习 文件名grepfile Steve Blenheim:238-923-7366:95 Latham Lane ...

  4. Shell学习:grep, sed, awk命令的练习题

    http://www.cnblogs.com/chengmo/archive/2013/01/17/2865479.html 文件:datafileSteve Blenheim:238-923-736 ...

  5. 【Linux】 字符串和文本处理工具 grep & sed & awk

    Linux字符串&文本处理工具 因为用linux的时候主要用到的还是字符交互界面,所以对字符串的处理变得十分重要.这篇介绍三个常用的字符串处理工具,包括grep,sed和awk ■ grep ...

  6. [svc]linux正则实战(grep/sed/awk)

    企业实战: 过滤ip 过滤出第二行的 192.168.2.11. eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 ine ...

  7. Linux基础命令-Nginx-正则表达式( grep sed awk )-Shell Script--etc

    Linux基础使用 学习内容博客 内存 查看swap分区信息 > swapon -s 添加swap分区 > mkswap /dev/sdb2 > 激活 swapon -a /dev/ ...

  8. linux grep,sed,awk和diff的使用

    1:grep//显示行 # grep 'main' /home/myhome/a.c//将a.c含有main的行显示出来 # grep -v 'main' /home/myhome/a.c //显示除 ...

  9. grep sed awk 3个Linux中对文件内容操作的命令

    在学习Linux命令中,发现3个有关于文件内容操作的命令grep,sed和awk,在这里简单汇总这3个命令主要作用,在实际中找到最合适的情景应用,详细用法可以参考其他文章. 1.grep命令 主要作用 ...

随机推荐

  1. C++ 重载关系操作符

    #include <iostream> using namespace std; class AAA { public: AAA() //默认构造 { } AAA(int id, stri ...

  2. 系统之眼!Linux系统性能监控工具Glances

    一.Glances介绍 glances是一个基于python语言开发,可以为linux或者UNIX性能提供监视和分析性能数据的功能.glances在用户的终端上显示重要的系统信息,并动态的进行更新,让 ...

  3. H5解决安卓软键盘弹出遮蔽的方法

    首先先判断是否为安卓,是的话才添加事件监听,获取焦点元素判断是否为input或者textarea类型,是的话,Element.scrollIntoView() 方法会让当前的元素滚动到浏览器窗口的可视 ...

  4. 快速排序--15--快排--LeetCode排序数组

    排序数组 给定一个整数数组 nums,将该数组升序排列. 示例 1: 输入:[5,2,3,1] 输出:[1,2,3,5] 示例 2: 输入:[5,1,1,2,0,0] 输出:[0,0,1,1,2,5] ...

  5. 基于.NetCore3.1搭建项目系列 —— 使用Swagger做Api文档 (上篇)

    前言 为什么在开发中,接口文档越来越成为前后端开发人员沟通的枢纽呢? 随着业务的发张,项目越来越多,而对于支撑整个项目架构体系而言,我们对系统业务的水平拆分,垂直分层,让业务系统更加清晰,从而产生一系 ...

  6. Python 之装饰器

    Python 的装饰器可谓是提高开发效率的一大利器.然而初学装饰器的时候感觉很难理解,因为除了 Python 之外没听说哪个语言有这种东西. 而且网上看的很多解释看似容易理解,但只能很快理解了装饰器能 ...

  7. kerberos系列之hdfs&yarn认证配置

    一.安装hadoop 1.解压安装包重命名安装目录 [root@cluster2_host1 data]# tar -zxvf hadoop-2.7.1.tar.gz -C /usr/local/ [ ...

  8. 14. java基于excel模板导出excel=>使用jxls最新版(注意点)

    注意点:如下: jxls官网:http://jxls.sourceforge.net/getting_started.html

  9. Error while importing sbt project:--创建sbt项目导入文件出错

    错误截图如下: Error while importing sbt project: List([info] Loading global plugins from C:\Users\RYJ\.sbt ...

  10. eclipse操作快捷键

    Eclipse最全快捷键,熟悉快捷键可以帮助开发事半功倍,节省更多的时间来用于做有意义的事情. Ctrl+1 快速修复(最经典的快捷键,就不用多说了) Ctrl+D: 删除当前行 Ctrl+Alt+↓ ...