This is my input file.
yyyy-mm-dd hh:mm:ss string *9999999999 [AAAAA]
yyyy-mm-dd hh:mm:ss string *5555555555 [AAAAA]
yyyy-mm-dd hh:mm:ss string *9999999999 [AAAAA]
yyyy-mm-dd hh:mm:ss string *9999999999 [AAAAA]
yyyy-mm-dd hh:mm:ss string *2222222222 [AAAAA]
yyyy-mm-dd hh:mm:ss string *9999999999 [AAAAA]
yyyy-mm-dd hh:mm:ss string *3333333333 [AAAAA]
yyyy-mm-dd hh:mm:ss string *9999999999 [AAAAA]
yyyy-mm-dd hh:mm:ss string *9999999999 [BBBBB]
yyyy-mm-dd hh:mm:ss string *6666666666 [AAAAA]
Let's consider the above input as input.gz, how to get the count of *9999999999 with last column as [AAAAAA]
I need a script using SED or AWK or GREP.
Expected output should be:
5
What if the above input has the last column extended to a new line? like:
yyyy-mm-dd hh:mm:ss string *9999999999 [AAAAA]
yyyy-mm-dd hh:mm:ss string *5555555555 [AAAAA]
yyyy-mm-dd hh:mm:ss string *9999999999 [AAAAA
zzzzzzzzzzzz xxxxxxxx yy]
yyyy-mm-dd hh:mm:ss string *9999999999 [AAAAA]
yyyy-mm-dd hh:mm:ss string *2222222222 [AAAAA]
yyyy-mm-dd hh:mm:ss string *9999999999 [AAAAA]
yyyy-mm-dd hh:mm:ss string *3333333333 [AAAAA]
yyyy-mm-dd hh:mm:ss string *9999999999 [AAAAA]
yyyy-mm-dd hh:mm:ss string *9999999999 [BBBBB]
yyyy-mm-dd hh:mm:ss string *6666666666 [AAAAA]
In the above case, won't it be difficult to use AWK? How to overcome this using SED?
I'm sorry for editing it again. What if the 10-digit number is unknown? like *9999999999 is unknown, can we find out the number of times *NNNNNNNNNN is occuring with last column as [AAAAA]?
In the above case, won't it be difficult to use AWK? How to overcome this using SED?. You have been misinformed. awk is specifically designed to operate on multi-line records. No exaggeration, sed hasn't been an appropriate tool to use on multi-line text since the mid-1970s when awk was invented. Really think about the most difficult input cases you need to handle and edit your question to show those plus the expected output given that input because right now the sample input you are providing doesn't seem to reflect worst cases of what you are describing.