0

I have my primary file(log1.txt) strings below.

T202210010515.XX.old:2022-10-01 10:57:56<Other Texts>975673849<0ther Texts>975673849
T202210010515.XX.old:2022-10-01 10:59:56<Other Texts>975673449<0ther Texts>975673449
T202210010515.XX.old:2022-10-01 10:57:58<Other Texts>975673849<0ther Texts>975673849
T202210010515.XX.old:2022-10-01 10:59:51<Other Texts>975673849<0ther Texts>975673849
T202210010515.XX.old:2022-10-01 10:57:52<Other Texts>975673849<0ther Texts>975673849
T202210010515.XX.old:2022-10-01 10:59:59<Other Texts>975673449<0ther Texts>975673449

Each and every set is starting with T202210*. I need to grep the number and return the lines count which that numbers occured. I have another secondary file with all the numbers which I need to search(numbers.txt). Here is what I need as the output, The Number and the lines count of each number.

975673849 -4
975673449 -2

Here is my try.

grep -f numbers.txt log1.txt

But this will produce all the string lines with a highlighted number. Can someone help me to produce the output what I need actually.

3
  • Can <Other Texts> contain digits?
    – Kusalananda
    Commented Oct 26, 2022 at 5:25
  • @Kusalananda Yes,
    – edublog
    Commented Oct 26, 2022 at 5:28
  • @edublog An actual sample of the data would be needed. In theory, from what you have told us, the log line may contain only digits after the datestamp, and it would therefore be very difficult to parse out the particular string of digits that you are looking for.
    – Kusalananda
    Commented Oct 26, 2022 at 5:31

1 Answer 1

1

That should work:

╰─$ cat log1.txt                                                                                                                                                                                             130 ↵
T202210010515.XX.old:2022-10-01 10:57:56<Other Texts>975673849<0ther Texts>975673849
 T202210010515.XX.old:2022-10-01 10:58:56<Other Texts>975673849<0ther Texts>975673849
╰─$ cat numbers.txt 
975673849
975673449
╰─$ while read -r line; do echo "$line" && cat log1.txt | grep -c "$line"  ; done < numbers.txt
975673849
2
975673449
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .