For:
echo "the quick brown fox" | grep -Po '[a-z]+ [a-z]+'
I get:
the quick
brown fox
but I wanted:
the quick
quick brown
brown fox
How?
with awk
:
awk '{for(i=1;i<NF;i++) print $i,$(i+1)}' <<<"the quick brown fox"
update: with python:
#!/usr/bin/python3.5
import re
s="the quick brown fox"
matches = re.finditer(r'(?=(\b[a-z]+\b \b[a-z]+\b))',s)
ans=[i.group(1) for i in matches]
print(ans) #or not print
for i in ans:
print(i)
output:
['the quick', 'quick brown', 'brown fox']
the quick
quick brown
brown fox
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With