grep无法匹配另一个文件中的1个文件的内容

时间:2015-12-15 08:02:22

标签: linux shell unix grep

Grep无法在另一个文件中搜索1个文件的内容,不知道出了什么问题。

有一个名为我的文件,其内容如

sadiadas

HTTP:STC:ACTIVEX:MCAFEE-FREESCN 
HTTP:STC:IMG:ANI-BLOCK-STR2 
HTTP:STC:ADOBE:PDF-LIBTIFF 
HTTP:STC:ADOBE:PS-PNG-BO 
HTTP:STC:DL:EOT-IO 
HTTP:STC:IE:CLIP-MEM 
HTTP:STC:DL:XLS-DATA-INIT 
HTTP:STC:ADOBE:FLASH-RUNTIME 
HTTP:STC:ADOBE:FLASH-ARGREST 
HTTP:STC:DL:MS-NET-CLILOADER-MC 
HTTP:ORACLE:COREL-DRAW-BO 
HTTP:STC:MS-FOREFRONT-RCE 
HTTP:STC:DL:VISIO-UMLSTRING 
HTTP:ORACLE:OUTSIDEIN-CORELDRAW 
HTTP:STC:DL:MAL-M3U 
HTTP:STC:JAVA:MIXERSEQ-OF 
HTTP:STC:DL:MAL-WEBEX-WRF 
HTTP:STC:DL:XLS-FORMULA-BIFF 
HTTP:STC:JAVA:TYPE1-FONT 
HTTP:STC:DL:XLS-FIELD-MC 
HTTP:STC:IE:AUTH-REFLECTION 
HTTP:STC:DL:MOZILLA-WAV-BOF 
HTTP:XSS:PHPNUKE-BOOKMARKS1 
HTTP:STC:DL:MAL-WIN-BRIEFCASE-2 
HTTP:STC:ADOBE:FLASH-INT-OV 
HTTP:STC:IE:MAL-GIF-DOS 
APP:NOVELL:GWMGR-INFODISC 
APP:SYMC:MESSAGING-SAVE.DO-CSRF 
HTTP:STC:ADOBE:READER-MC-RCE 
HTTP:STC:DL:SOPHOS-RAR-VMSF-RGB 
HTTP:ORACLE:OUTSIDE-IN-PRDOX-BO 
HTTP:STC:JAVA:IBM-RMI-PROXY-RCE  
HTTP:STC:IE:REMOVECHILD-UAF 
HTTP:STC:COREL-WP-BOF 
SHELLCODE:MSF:PROPSPRAY 
HTTP:VLC-ABC-FILE-BOF 
HTTP:MISC:MS-XML-SIG-VAL-DOS 
HTTP:STC:ADOBE:FLASH-PLAYER-BOF 
HTTP:STC:ADOBE:FLASHPLR-FILE-MC 
HTTP:STC:ADOBE:FLASH-AS3-INT-OV 
HTTP:ORACLE:OUTSIDE-IN-MSACCESS 
HTTP:STC:SCRIPT:APACHE-XML-DOS 
HTTP:STC:JAVA:METHODHANDLE 
HTTP:STC:ADOBE:CVE-2014-0506-UF 
HTTP:STC:IE:CVE-2014-1789-MC 
HTTP:STC:ACTIVEX:KVIEW-KCHARTXY 
SHELLCODE:X86:LIN-SHELL-REV-80S 
HTTP:STC:JAVA:JRE-PTR-CTRL-EXEC 
HTTP:STC:ADOBE:CVE-2015-0091-CE 
HTTP:DOS:MUL-PRODUCTS 
HTTP:MISC:WAPP-SUSP-FILEUL1 
SHELLCODE:X86:BASE64-NOOP-80C 
SHELLCODE:X86:BASE64-NOOP-80S 
SHELLCODE:X86:REVERS-CONECT-80C 
SHELLCODE:X86:REVERS-CONECT-80S 
SHELLCODE:X86:FLDZ-GET-EIP-80C 
SHELLCODE:X86:FLDZ-GET-EIP-80S 
SHELLCODE:X86:WIN32-ENUM-80C 
SHELLCODE:X86:WIN32-ENUM-80S 

和另一个文件1的文件名为2537_2550

HTTP:STC:OUTLOOK:MAILTO-QUOT-CE  
HTTP:STC:HSC:HCP-QUOTE-SCRIPT  
HTTP:STC:HSC:MS-HSC-URL-VLN  
HTTP:STC:TELNET-URL-OPTS  
HTTP:STC:NOTES-INI  
HTTP:STC:MOZILLA:SHELL  
HTTP:STC:RESIZE-DOS  
HTTP:STC:IE:SHELL-WEB-FOLDER  
HTTP:STC:IE:IE-MHT-REDIRECT  
HTTP:IIS:ASP-DOT-NET-BACKSLASH  
APP:SECURECRT-CONF  
HTTP:STC:IE:IE-FTP-CMD  
HTTP:STC:IE:URL-HIDING-ENC  
HTTP:STC:MOZILLA:IFRAME-SRC  
HTTP:STC:JAVA:MAL-JNLP-FILE  
HTTP:STC:MOZILLA:WRAPPED-JAVA  
HTTP:STC:MOZILLA:ICONURL-JS  
APP:REAL:PLAYER-FORMAT-STRING  
HTTP:STC:IE:FULLMEM-RELOAD  
HTTP:STC:DL:PPT-SCRIPT  
HTTP:STC:MOZILLA:FIREUNICODE  
HTTP:STC:IE:MULTI-ACTION  
HTTP:STC:IE:CREATETEXTRANGE  
HTTP:STC:IE:HTML-TAG-MC  
HTTP:STC:IE:NESTED-OBJECT-TAG  
SHELLCODE:JS:UNICODE-ENC  
HTTP:STC:IE:UTF8-DECODE-OF  
HTTP:STC:IE:VML-FILL-BOF  
HTTP:STC:MOZILLA:FF-DEL-OBJ-REF  
HTTP:STC:ADOBE:ACROBAT-URL-DF  
HTTP:STC:CLSID:ACTIVEX:TREND-AX  
HTTP:XSS:IE7-XSS  
HTTP:STC:NAV-REDIR  
HTTP:STC:ACTIVEX:AOL-AMPX  
HTTP:STC:ACTIVEX:IENIPP  
HTTP:STC:ACTIVEX:REAL-PLAYER  
HTTP:STC:ACTIVEX:ORBIT-DWNLDR  
HTTP:STC:SEARCH-LINK  
HTTP:STC:ITUNES-HANDLER-OF  
HTTP:STC:OPERA:FILE-URL-OF  
HTTP:STC:ACTIVEX:EASYMAIL  
HTTP:STC:ACTIVEX:IETAB-AX  
HTTP:STC:ADOBE:PDF-LIBTIFF  
HTTP:STC:IE:TOSTATIC-DISC  
HTTP:STC:WHSC-RCE  
HTTP:STC:IE:CROSS-DOMAIN-INFO  
HTTP:STC:IE:UNISCRIBE-FNPS-MC  
HTTP:STC:IE:CSS-OF  
HTTP:STC:OBJ-FILE-BASE64  
HTTP:STC:IE:ANIMATEMOTION  
HTTP:STC:CHROME:GURL-XO-BYPASS  
HTTP:STC:SAFARI:WEBKIT-1ST-LTR  
HTTP:STC:IE:BOUNDELEMENTS  
HTTP:STC:IE:IFRAME-MEM-CORR  
HTTP:STC:STREAM:QT-HREFTRACK  
HTTP:STC:MOZILLA:CONSTRUCTFRAME  
HTTP:STC:MOZILLA:ARGMNT-FUNC-CE  
HTTP:STC:ADOBE:PS-PNG-BO  
HTTP:STC:IE:HTML-RELOAD-CORRUPT  
HTTP:STC:IE:TABLE-SPAN-CORRUPT  
HTTP:STC:IE:TABLE-LAYOUT  
HTTP:STC:DL:MSHTML-DBLFREE  
HTTP:STC:IE:EVENT-INVOKE  
HTTP:STC:IE:DEREF-OBJ-ACCESS  
HTTP:STC:IE:TOSTATIC-XSS  
HTTP:STC:ON-BEFORE-UNLOAD  
HTTP:STC:DL:MAL-WOFF  
HTTP:STC:DL:EOT-IO  
HTTP:STC:MOZILLA:FF-REMOTE-MC  
HTTP:STC:DL:DIRECTX-SAMI  
HTTP:STC:IE:ONREADYSTATE  
HTTP:STC:DL:VML-GRADIENT  
HTTP:STC:IE:TABLES-MEMCORRUPT  
HTTP:STC:JAVA:DOCBASE-BOF  
HTTP:STC:IE:CLIP-MEM  
HTTP:STC:ACTIVEX:WMI-ADMIN  
HTTP:STC:MOZILLA:DOC-WRITE-MC  
HTTP:STC:IE:SELECT-ELEMENT  
HTTP:STC:IE:XML-ELEMENT-RCE  
SHELLCODE:X86:FNSTENV-80C  
HTTP:STC:IE:OBJ-MGMT-MC  
HTTP:STC:DL:XLS-DATA-INIT  
HTTP:STC:ADOBE:FLASH-RUNTIME  
HTTP:STC:ACTIVEX:ISSYMBOL  
HTTP:STC:ADOBE:FLASH-ARGREST  
HTTP:STC:IE:VML-RCE  
HTTP:STC:IE:HTML-TIME  
HTTP:STC:IE:LAYOUT-GRID  
HTTP:STC:IE:CELEMENT-RCE  
HTTP:STC:IE:SELECT-EMPTY  
HTTP:XSS:MS-IE-TOSTATICHTML  
HTTP:STC:SAFARI:WEBKIT-FREE-CE  
HTTP:IIS:ASP-PAGE-BOF  
HTTP:STC:MOZILLA:FIREFOX-MC  
HTTP:STC:MOZILLA:FF-XSL-TRANS  
HTTP:STC:DL:MS-NET-CLILOADER-MC  
HTTP:STC:MOZILLA:CLEARTEXTRUN  
HTTP:STC:MOZILLA:FIREFOX-ENG-MC  
HTTP:STC:MOZILLA:PARAM-OF  
HTTP:ORACLE:COREL-DRAW-BO  
HTTP:STC:MOZILLA:JIT-ESCAPE-MC  
HTTP:STC:SAFARI:WEBKIT-SVG-MC  
HTTP:STC:SAFARI:INNERHTML-MC  
HTTP:STC:MOZILLA:NSCSSVALUE-OF  
HTTP:NOVELL:GROUPWISE-IMG-BOF

我试过

grep -Ff mine 2537_2550但是grep无法搜索?

2 个答案:

答案 0 :(得分:1)

准确使用您的输入和命令,我可以找到匹配的行:

$ grep -Ff file1 file2
HTTP:STC:ADOBE:PDF-LIBTIFF
HTTP:STC:ADOBE:PS-PNG-BO
HTTP:STC:DL:EOT-IO
HTTP:STC:IE:CLIP-MEM
HTTP:STC:DL:XLS-DATA-INIT
HTTP:STC:ADOBE:FLASH-RUNTIME
HTTP:STC:ADOBE:FLASH-ARGREST
HTTP:STC:DL:MS-NET-CLILOADER-MC
HTTP:ORACLE:COREL-DRAW-BO

可能你有一些不可打印的角色阻止你找到匹配。

尝试使用以下命令从两个文件中删除不可打印的字符:

tr -cd '\11\12\15\40-\176' < infile > outfile

答案 1 :(得分:1)

我已经使用了你提到的输入数据并且它正在运行。 给出以下输出

$ grep -Ff pattern searchFile HTTP:STC:ADOBE:PDF-LIBTIFF HTTP:STC:ADOBE:PS-PNG-BO HTTP:STC:DL:EOT-IO HTTP:STC:IE:CLIP-MEM HTTP:STC:DL:XLS-DATA-INIT HTTP:STC:ADOBE:FLASH-RUNTIME HTTP:STC:ADOBE:FLASH-ARGREST HTTP:STC:DL:MS-NET-CLILOADER-MC HTTP:ORACLE:COREL-DRAW-BO

您的文件中可能存在一些不可打印的字符。 使用cat -vte filename来查找它们。 如果您的文件已从某些不同的OS服务器(如Windows)中删除,请使用dos2unix filename将其转换为unix文件格式