简体   繁体   English

使用ack搜索没有扩展名的文件

[英]Using ack to search inside files with no extensions

I have some text "bar" contained in files FOO and foo.cc . 我有一些文本“bar”包含在文件FOOfoo.cc

Is there a way to tell ack-grep to search inside files with no extension (namely FOO )? 有没有办法告诉ack-grep搜索没有扩展名的文件(即FOO )?

I've tried something like this: 我尝试过这样的事情:

ack-grep --type-set=foo=FOO bar

which returns the text in foo.cc, but not file FOO. 它返回foo.cc中的文本,但不返回文件FOO。

I've also added the --type-set to my .ackrc file, calling 我还将--type-set添加到我的.ackrc文件中,调用

ack-grep --help-types

shows that ack-grep is looking for .FOO files. 表明ack-grep正在寻找.FOO文件。

My ack is of version 2.12. 我的ack是版本2.12。 Bellow command should work. 贝娄的命令应该有效。

$ ack --type-set make:is:Makefile --type=make string-pattern

So similarly, 所以类似地,

$ ack --type-set foo:is:FOO --type=foo string-pattern

You can combine ack-grep 's -a (search everything) with -G (only search files that match a given regex). 您可以将ack-grep-a (搜索所有内容)与-G (仅搜索与给定正则表达式匹配的文件)组合在一起。 Something like: 就像是:

ack-grep -a -G '^[^.]+$' what-to-search-for

should do the trick. 应该做的伎俩。

Under ack2 you have to define a custom type: 在ack2下,您必须定义自定义类型:

ack-grep --WANTED --type-set WANTED:match:^[^.]+$ what-to-search-for

works for me. 适合我。

You cannot do what you want with ack 1.x. 你无法用ack 1.x做你想做的事。 You need to upgrade to ack 2.0 . 您需要升级到ack 2.0

ack 1.x did not have a way to deal with files without extensions. ack 1.x没有办法处理没有扩展名的文件。 ack 2.0 adds a much more flexible file-specification system. ack 2.0增加了一个更加灵活的文件规范系统。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM