For example, there is the string Aaaaaaaaabbbbbb. The output should get Aaaaaaaaa9bbbbbb6

Bach newbie. Is there any need to try to loop through the string in a symbolic way, compare it with the previous value, increase the counter if the values ​​are equal and overwrite it in a new line. If so, how to do it in bash? I would be grateful for any help.

  • a clarification is clearly required: do you need to implement it with the language tools of the shell, or, which is simpler, but more resource-intensive, using the tools of the gnu operating system ( coreutils + (sed | awk) )? - aleksandr barakin
  • Well, in general, about educational tasks, you know? and the algorithm is elementary - just like for any programming language: sorting the characters one by one, if the next character does not match the previous one, we display the value of the counter and reset it, otherwise we increase the value of the counter by one. - aleksandr barakin
  • In Perl, this can be done very easily. - Wiktor Stribiżew
  • @alexander barakin What is simpler - Vadim Moroz
  • In order to have something simpler, you must first write something complicated. What did you do? - Wiktor Stribiżew

0