Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I grep 2 occurrences of string "ATAT" out of string "ATATAT". I only get one

Tags:

regex

grep

I am trying to write a command to grep the number of occurrences in a string, but my string is "ATATAT" and I want to grep "ATAT". I am expecting to get 2 outputs when I use command I get only 1.

echo "ATATAT" |grep -o "ATAT" 

I have tried surrounding the string with ** but still it only matches one pattern.

like image 901
Sherif Negm Avatar asked Dec 31 '22 19:12

Sherif Negm


1 Answers

The simplest way - make Python do it for you:

python -c "import re; print(re.findall(r'(?=(ATAT))', 'ATATAT'))"
['ATAT', 'ATAT']
like image 73
CIsForCookies Avatar answered Jan 07 '23 19:01

CIsForCookies