AWK - I need to write a one line shell command that will count all lines that

后端 未结 2 690
天涯浪人
天涯浪人 2021-01-27 10:54

I need to write this solution as an AWK command. I am stuck on the last question:


Write a one line shell command that will count all lines in a file called \"f

2条回答
  •  孤独总比滥情好
    2021-01-27 11:22

    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 ' {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 '' file.txt | wc -l
    

    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.

    Now as to what the condition should be, I leave to you. I strongly suggest that you google regular expressions and awk, it shouldn't be too hard.

提交回复
热议问题