0

With a file of integers separated by newlines, I would like to search for consecutive integers, then list the amount of integers that are consecutive per uninterrupted sequence, as well as the direction (ascending or descending) that each sequence is going in.

My file looks something like this:

2
3
4
5
1
7
4
5
6
3
2
1

And my desired output would be:

4^
3^
3v

With the first character indicating the amount of numbers that are consecutive, and the second character indicating whether the numbers are ascending or descending. Is there a way to do this in bash?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.