简体   繁体   English

在文件中查找字符串并输出结果

[英]Finding a string within a file and outputting results

I would like grab one line (1 term) at a time from file1.txt and search sFile.txt... outputting all the lines that have the found term in it.我想一次从 file1.txt 中抓取一行(1 个术语)并搜索 sFile.txt... 输出其中包含找到的术语的所有行。 file1.txt (300 lines) sFile.txt (100k lines) . file1.txt(300 行) sFile.txt(10 万行) I would like to use a command line (linux) fgrep , ack , find , etc. I have tried a fgrep command but I am hitting the character limit so nothing is being processed.我想使用命令行 (linux) fgrepackfind等。我尝试了 fgrep 命令,但我达到了字符限制,因此没有处理任何内容。

tried: fgrep -wi 'front1' test.log >> final.txt this worked but when adding file1.txt the process was not able to run试过: fgrep -wi 'front1' test.log >> final.txt这有效,但在添加file1.txt ,进程无法运行

file1.txt structure (case insensitive) file1.txt结构(不区分大小写)

front1
front2
FrOnT3

sFile.txt structure sFile.txt结构

106.4 - - [12/Aug/2020:10:46:57 -0400] "GET /skin/front1/sharp_bootstrap/default/css"
106.4 - - [12/Aug/2020:10:46:57 -0400] "GET /skin/front3/sharp_bootstrap/default/css"
106.4 - - [12/Aug/2020:10:46:57 -0400] "GET /skin/front2/sharp_bootstrap/default/css"
106.4 - - [12/Aug/2020:10:46:57 -0400] "GET /skin/front0/sharp_bootstrap/default/css"

final.txt three lines should have been found final.txt三行应该已经找到了

106.4 - - [12/Aug/2020:10:46:57 -0400] "GET /skin/front1/sharp_bootstrap/default/css"
106.4 - - [12/Aug/2020:10:46:57 -0400] "GET /skin/front3/sharp_bootstrap/default/css"
106.4 - - [12/Aug/2020:10:46:57 -0400] "GET /skin/front2/sharp_bootstrap/default/css"

稍微修改@thanasisp 所说的,如果您使用以下内容,您是否没有获得所需的输出?

grep -if file1.txt sFile.txt

我找到了解决方案... 解决方案来源

fgrep -v -F -f file1.txt sFile.txt

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

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