In this blog, sharing the code to remove consecutively repeated characters in a String. Consider a String “allabouttechnologies” . Here, l and t are repeated Characters. So, after applying logic, it will be like “alaboutechnologies“. str=”alllabouttechnologies” ##Sample Stringnewstr=” ##new Blank Stringn=${#str} ##length of a Sample StringPrevChar=${str:0:1} ##First Character of a Stringi=1while [[ $i -le $n ]] ##Looping Character by CharacterdoNextChar=${str:$i:1}if [[ $PrevChar == $NextChar ]] ##if two consecutive Character matches, it will remove or ignore the matched one and keep repeated Character oncethenecho “Ignore this Character: “$NextCharelsenewstr=${newstr}${PrevChar} ##merging only non-repeated…
Tag: length of a string in linux
Find first repeated character
In this blog, sharing the code to find the first repeated Character in a string. Consider a String “allabouttechnologies“, here l and t are the repeated Characters but l is the first repeated Character. str=”allabouttechnologies” ## Sample Stringn=${#str} ##Length of a StringPrevChar=${str:0:1} ## Set PrevChar as first character of a Stringi=1while [[ $i -lt $n ]] ## Looping through each character of a stringdoNextChar=${str:$i:1} ## Assigning NextChar equals to current Character in the Loopif [[ $PrevChar == $NextChar ]] ## Comparing consecutive Characters of a string in a loop, if…