简体   繁体   English

如何通过管道将输出重定向到wc?

[英]How to redirect an output to wc by pipeline?

count=`cat "Main Dir/$param/sent.txt"|sort -k2|tail -n-$LAST_SENT_EMAILS_TO_CONSIDER|cut -f1 -d" " -d"  "|cut -f2 -d"@"|cut -f1 -d"."|wc -w $domain`

Until the wc, I take "LAST_SENT_EMAILS_TO_CONSIDER" strokes from sent.txt sorted by some parameter that I took. 在开始wc之前,我从send.txt中获取“ LAST_SENT_EMAILS_TO_CONSIDER”笔划,并按我采用的某些参数进行了排序。

Now, I want to count how much the content of domain ($domain) repeat in the cut strokes. 现在,我要计算在笔触中重复的域($ domain)的内容。

I did see similar questions and answers, which say that by reorganizing that command line in other way, it could work. 我确实看到了类似的问题和答案,它们表示通过以其他方式重组该命令行可以正常工作。 Can somebody help me with this concrete example? 有人可以帮我这个具体的例子吗?

Without knowing the input, I can't test my solution. 不知道输入内容,就无法测试我的解决方案。 But if I understand you correctly, you just want to do 但是,如果我理解正确,那么您只想做

... | grep -F "$domain" | wc -l

ie count how many times $domain appears in the output. 即计算$ domain在输出中出现多少次。 -F is used to prevent interpreting of special characters (eg . normally matches anything, but if your domain is example.com , you don't want to match exampleXcom ). -F用于防止特殊字符的解释(例如.通常匹配任何内容,但是如果您的域是example.com ,则您不希望匹配exampleXcom )。

BTW, grep can count the line itself, so you can shorten it to 顺便说一句, grep可以自己计算行数,因此您可以将其缩短为

... | grep -Fc "$domain"

Apology, my mistake, wc doesn't count <"expressions">, but only words, strokes or chars. 道歉,我的错, wc不算<“ expressions”>,而只算单词,笔画或字符。

Yes, as choroba said, that's what I wanted to do, and I can use for it only: 是的,正如choroba所说,这就是我想要做的,并且我只能使用它:

...|grep -c "$domain"

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

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