regex - grep Regex 在文件中查找特定单词

标签 regex linux grep

我有一个文件,内容如下:

this is text file, \"value\":\"ABCD1000\" , this file contains some weird text, \"value\":\"ABDFD1000\" ...

我想提取所有值,如“value :ABDC1000”

I am using grep command as: grep -o '"value\\":\\\"[a-zA-Z0-9]+\\\"' file.name 

但是它没有给出任何输出。

我在这里做错了什么。

我用了http://regexr.com/检查我的正则表达式,它看起来是正确的。

最佳答案

使用 GNU grep:

grep -o '\\"value\\":\\"[^\\]*\\"' file | tr -d '\\"'

输出:

value:ABCD1000
value:ABDFD1000

关于regex - grep Regex 在文件中查找特定单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35094660/

相关文章:

regex - 使用 sed 和正则表达式删除前缀

javascript - 我用于查找多个空格的正则表达式如何不匹配换行符?

以符号开头的 Linux 目录文件夹

linux - 从 Bash 脚本执行 GREP/CUT 命令时出现问题

regex - 使用正则表达式匹配字符串

bash - 使用 find、grep、sed 的 bash 脚本中的段错误

regex - 什么是验证字符串只有字母数字和连字符的惯用 clojure?

php - preg_match_all 查找某个字符串之后的所有单词

javascript - 如何通过命令解析以在 Node JS 中接收带有子进程的特定行

linux - Linux有时会检测到声卡