grep 查找包含 " 的行 " [英] grep find lines that contains " "

查看:20
本文介绍了grep 查找包含 " 的行 "的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被要求制作一个 shell 脚本来检查文件中的简单错误.我想找到,对于每一行如果

I was requested to make a shell script to check for simple mistakes in files. I wanted to find, for each line if

(regex:) "[ ] " 曾​​经发生过.

(regex:) "[ ] " ever happens.

问题在于 grep 忽略了 并将t"作为字面量.我还尝试将字符本身写入文件并要求 grep 读取它,但没有奏效.有没有办法使用任何常用的 linux 工具(如 grep)在文件中查找正则表达式 "?

The problem is that grep is ignoring the and is taking "t" as a literal. I also tried writting the characters themselves in a file and asking grep to read it but it didn't work. Is there a way to find for the regex " " in files using any of the usual linux tools (like grep)?

我已经试过了:

grep -E --ignore-case --line-number --with-filename --file="b" file

(b 包含:" ")还有:

(b contains: " ") and also:

grep -E --ignore-case --line-number --with-filename --regexp=" [	]" file

推荐答案

你可以使用 C 风格的字符串 $'...'

You can use C-style string $'...'

grep $'	' file.txt

sed:

sed -n '/	/p' file.txt

这篇关于grep 查找包含 " 的行 "的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆