Unix'find'+'grep'语法与awk [英] Unix 'find' + 'grep' syntax vs. awk

查看:164
本文介绍了Unix'find'+'grep'语法与awk的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用这一行在我所在的目录及其所有子目录中的文件中找到B206这个词组。 code> find。 -exec grep -sB206'{}'\; -print

当它试图读取某些文件并且实际上将putty中的标题栏更改为一堆奇怪的字符



例如,当它碰到一个子目录下的jpg文件时,它一直崩溃。标题栏变化,并在屏幕上,存在:

 ÐF»*rkNQeË+ Z׳kU£MÞçÄZ½ªéúýØâÑn[ U +Þ4ª9/꣯4} [IÓîK»G%ݳ¢

强迫我Ctrl + C出来回到提示,然后退出。

任何方式添加代码到这一行,将排除jpg文件?更好的是,我可以添加一个扩展名列表排除一个代码片段?



编辑:

-not& - 我不为我工作

我发现这个

  find。 | awk'!/((\.jpeg)|(\.jpg)|(\.png))$ / {print $ 0;}'| xargs grepB206


I was using this line to find the phrase, 'B206' within files in the directory I was in and all of its sub directories.

find . -exec grep -s "B206" '{}' \; -print 

It crashes when it tries to read certain files and actually changes the title bar in putty to a bunch of weird characters

For example, it crashes all the time when it hits a jpg file that's in a sub directory. The title bar changes, and in the screen, there exists:

ÐF»*rkNQeË+Z׳kU£~MÞçÄZ½ªéúýØâÑn¡[U+Þ4ªÒ9/ê£<ú¯4}[IÓ­îÃ¥K»G%ݳ¢

Forcing me to Ctrl+C out back to the prompt and then exit out.

Any way to add code to this line that will exclude jpg files? Even better, a piece of code where I can add a list of extensions to exclude?


EDIT:
-not & -I do not work for me
I found this
similar question also related somewhat to mine

解决方案

If your environment can't do any fancy grep, maybe your awk can do it:

find . | awk '!/((\.jpeg)|(\.jpg)|(\.png))$/ {print $0;}' | xargs grep "B206"

这篇关于Unix'find'+'grep'语法与awk的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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