AWK - 我需要写一行shell命令,将计算所有行了 [英] AWK - I need to write a one line shell command that will count all lines that
问题描述
我需要写这个解决方案作为一个AWK命令。我被困在了最后一个问题:
I need to write this solution as an AWK command. I am stuck on the last question:
的写一行shell命令,将计算一个名为file.txt的与括号十进制数字开头文件中的所有行,同时包含大小写字母的组合,并配有结束期。的
例(S):
这就是我们要打印线的格式。不符合此格式的行应该被忽略:
(10)这是一个file.txt文件示例行,你的脚本应该
计数。
(10) This is a sample line from file.txt that your script should count.
(117),这是另一行脚本应该算。
(117) And this is another line your script should count.
行这样的,以及其他不匹配的行,应该忽略:
15这一行应该不会被打印
15 this line should not be printed
和此行不应被打印
在此先感谢,我真的不知道如何在一个放线滑车这一点。
Thanks in advance, I'm not really sure how to tackle this in one line.
推荐答案
这是不是一门功课的解决方案服务。但我认为我可以给一些指点。
This is not a homework solution service. But I think I can give a few pointers.
一个想法是创建一个计数器,然后在最后打印出结果:
One idea would be to create a counter, and then print the result at the end:
awk '<COND> {c++} END {print c}'
我得到一点点的术语混淆。首先你声称行应该算,但在例子中,它说,这些行应打印。
I'm getting a bit confused by the terminology. First you claim that the lines should be counted, but in the examples, it says that those lines should be printed.
现在当然,你可以做这样的事情:
Now of course you could do something like this:
awk '<COND>' file.txt | wc -l
的第一部分将打印出遵循的条件的所有行,但输出将被解析到 WC -l </ code>这是一个计数的行数一个单独的程序
The first part will print out all lines that follow the condition, but the output will be parsed to wc -l
which is a separate program that counts the number of lines.
现在作为条件的&LT什么; COND&GT;
应该是,我离开你。我强烈建议你谷歌经常EX pressions和awk,它不应该是太辛苦了。
Now as to what the condition <COND>
should be, I leave to you. I strongly suggest that you google regular expressions and awk, it shouldn't be too hard.
这篇关于AWK - 我需要写一行shell命令,将计算所有行了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!