Search

bash split string every n characters

bash split string every n characters
Today I needed to split a string in bash every 5 characters. Here is how I did it: a="AdmitAfritAmbitAuditAwaitBefitBinitBruitCubitDavitDebitDemitDigitDixitDroitFixitFruitHabitKraitLegitLicitLimitMeritOrbitPetitPewitPipitPlaitPositQubitQuoitRecitRefitRelitRemitResitSpaitSplitSpritTacitTraitUnfitUnlitUnwitUplitVisitVomitZizit" count=5 # change 5 to however many characters you wish to break on b="$a" while ; do echo "${b:0:$count}" b="${b:$count}" done I hope this snippet helps somebody. If it does, please feel free to leave a comment... Read More