AWK - I need to write a shell command with one line that will read all the lines that

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


Write a command line command with one line that will count all lines in a file called "file.txt" that begin with a decimal number in brackets containing a combination of upper and lower case letters and end with a period.

Example (s):

This is the format of the lines we want to print. Lines that do not conform to this format should be skipped:

(10) This is an example of a line from file.txt that your script should count.

(117) And this is another line that your script should calculate.

Lines like this, as well as other inconsistent lines, should be skipped:

15 this line should not be printed

and this line should not be printed


Thanks in advance, I'm not quite sure how to handle this in one line.

0
source share
2 answers

This is not a home solution. 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 am a little confused by the terminology. You first state that the lines should be counted, but the examples say that these lines should be printed.

Now, of course, you can do something like this:

awk '<COND>' file.txt | wc -l

, , wc -l, , .

, <COND>, . google awk, .

+1

,

, "file.txt", , .

1. begin with a decimal number in parenthesis
2. containing a mix of both upper and lower case letters
3. end with a period

. , 2. "", , .

, , , , wc script; , , .

, - , ...

0

All Articles