Linux命令行的正则表达式 [英] Linux command line regex

查看:133
本文介绍了Linux命令行的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想搜索到目录中的所有文件对于像@LBL_18989@LBL_15459字符串结尾用.M,@LBL_14359...

I would like to search into directory for all files end by .m for string like @"LBL_18989" @"LBL_15459" , @"LBL_14359" ...

我的命令是:

find . type f -name \*.m | grep '@"LBL_[[0-9]"]+' 

但它不工作:(

推荐答案

您应该总是给你的论点。您的查找-name模式包含一个*,这意味着shell将尝试通过它找到之前扩大它作为一个水珠。您还可以使用-regex应该找到的输出管道到grep的。

You should always quote your arguments. Your -name pattern for find contains an "*", which means the shell will try to expand it as a glob before passing it to find. You can also use -regex instead of piping the output of find to grep.

find . -type f -regex '@"LBL_[[:digit:]"]+'

基于JDI的评论

,你可能会想搜索这些文件的内容,对于给定的正则表达式。如果是这样,你可以使用以下内容:

Based on jdi's comment, you may be wanted to search the contents of those files for the given regex. If so, you can use the following:

find . type f -name '*.m' -exec grep -E '@"LBL_[[:digit:]"]+' /dev/null {} +

这篇关于Linux命令行的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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