This IS kind of linked to another question - Code golf: "Color highlighting" of repeated text
I'm tying to figure out a way of breaking a file into all 'n' characters long groups.
Eg: If a file comprises of ONLY the following text:
ABCDEFGHIJ
And we want it broken into sets of 3, the output should be:
ABC
BCD
CDE
DEF
EFG
FGH
GHI
HIJ
No characters in the file are to be treated any differently from another. ie, a "space" is just another character which should follow the rule above...
Does it have to be shell based or are you open to other scripting languages? Here's a version in Python:
sed:
A more generalized
sed
version:Bash and ksh:
zsh:
sh (specifically Dash):
AWK:
Edit: Added a more generalized
sed
version and an AWK version.