WelcomeUser Guide
ToSPrivacyCanary
DonateBugsLicense

©2025 Poal.co

753

(post is archived)

[–] 2 pts (edited )

Generating a list of Fibonacci numbers is tricky since they get big quickly, so I just found a . I removed the numbering with cut -f2. Then run your file and this list through grep.

cat test.txt

1 2 3 4 5 6 7 8 9 10 11 12 13

cat fib.txt

0 1 1 2 3 5 8 ...

grep -w -F -f fib.txt test.txt

1 2 3 4 5 6 7 8 9 10 11 12 13

Add -o to only print the matched words, one per line.

grep -o -w -F -f fib.txt test.txt

1 2 3 5 8 13

Don't write code if you don't need to, unless this is an exercise to learn a particular language.

EDIT: I see, you want the nth words of a text, for only n that are in the Fibonacci sequence.