Awk-- splitting a string into sub-strings with length n
awk
Solution
With `gawk` you can also do:
$ echo 'abcdefgh' | awk -F '' '{ for(i=1; i<=NF; i+=2) {printf "%s%s ", $i,$(i+1);}}'
ab cd ef gh
From gawk manual:
FS == ""
Each individual character in the record becomes a separate field. (This is a gawk extension; it is not specified by the POSIX standard.)
Problem
I am familiar with function split() which is used in awk programs. I was wondering how I can use it to split a string into smaller strings with length of n? Something like (n is set at 2): input: ``` abcdefgh ``` output: ``` ab cd ef gh ```