grep -Ff产生无效输出 [英] grep -Ff producing invalid output

查看:259
本文介绍了grep -Ff产生无效输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用

代码 -

  grep  - Ff list.txt C:/ data / *。txt> found.txt 

但它会持续输出无效的回复,行不包含我输入的电子邮件。

list.txt包含 -

  email@email.com 
customer@email.com
imadmin@gmail.com
newcustomer@email.com
helloworld@yes.com

等等。电子邮件在每一行上匹配,

搜索文件包含 -

  user1:phonenumber1:email@email.com:last-active:recent 
user2:phonennumber2:customer@email.com:last- active:inactive
user3:phonenumber3:blablarandom@bla.com:last-active:never

然后另一个可能包含 -

  blublublu email@email.com电话号码订阅
nanananana customer@email.com电话号码退订
useruser noemailinput@noemail.com电话号码未决

m试图做的是将grep与电子邮件/字符串列表list.txt一起呈现,然后搜索为每个字符串匹配提供的目录并输出包含每个匹配的整行。



在这种情况下,输出的例子是 -

  user1:phonenumber1:email@email.com :最近活动:最近
user2:phonennumber2:customer@email.com:最后活动:不活动
blublublu email@email.com phonenumber认购
nanananana customer@email.com phonenumber取消订阅

但它不会输出其他两行 -

  user3:phonenumber3:blablarandom@bla.com:last-active:never 
useruser noemailinput@noemail.com phonenumber pending

因为没有字符串在该行内。

解决方案

<我认为你的文件 list.txt 可能有空行在它中,使它匹配用 C:/ data / *。txt 指定的文件中的每一行。要解决您的问题,您可以手动删除每一个空行或运行命令 sed -i'/ ^ $ / d'list.txt 其中 -i 标志编辑文件到位。



这个问题也可能与dos回车有关,试试运行: cat -v list.txt 并检查行是否跟着 ^ M

  email@email.comM 
customer@email.comM

如果是这种情况,您需要使用 dos2unix tr -d'\r' < list.txt> output.txt


I'm using

code -

 grep -Ff list.txt C:/data/*.txt > found.txt

but it keeps outputting invalid responses, lines don't contain the emails i input..

list.txt contains -

email@email.com
customer@email.com
imadmin@gmail.com
newcustomer@email.com
helloworld@yes.com

and so on.. email to match on each line,

search files contain -

user1:phonenumber1:email@email.com:last-active:recent
user2:phonennumber2:customer@email.com:last-active:inactive
user3:phonenumber3:blablarandom@bla.com:last-active:never

then another may contain -

blublublu         email@email.com         phonenumber         subscribed
nanananana        customer@email.com      phonenumber         unsubscribed
useruser          noemailinput@noemail.com       phonenumber      pending

so what I'm trying to do is present grep with a list of emails/list of strings " list.txt " and to then search the directory provided for matches of each string and output the entire line that contains each match.

example of output in this case would be -

user1:phonenumber1:email@email.com:last-active:recent
user2:phonennumber2:customer@email.com:last-active:inactive
blublublu         email@email.com         phonenumber         subscribed
nanananana        customer@email.com      phonenumber         unsubscribed

yet it wouldn't output the other two lines -

 user3:phonenumber3:blablarandom@bla.com:last-active:never
 useruser          noemailinput@noemail.com       phonenumber      pending

because no string is within that line.

解决方案

I think your file list.txt may have blank lines in it, causing it to match every line in the files specified with C:/data/*.txt. To fix you can either manually delete every empty line or run the command sed -i '/^$/d' list.txt where the -i flag edits the file in place.

The issue may also be related to dos carriage returns, try running: cat -v list.txt and checking if the lines are followed by ^M:

email@email.com^M
customer@email.com^M

If this is the case you will need to amend the file using either dos2unix or tr -d '\r' < list.txt > output.txt.

这篇关于grep -Ff产生无效输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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