Reading files using AWK or SED

hi Friends,

Please help me to give a try for writing a shell script either with awk or SED for the below requirement.

i have file with 3 lines, each of size 3200 chars, wanted to read this file and divide eachline with 200 columns with differensizes for each column value by keeping seperator.

input:

asdfghjkkkkkkkkkkkkkkkkkkkkkkjjjjjjjjjjjuuuuuuuuuuuuu
zxccvbnmlkjhgfdsaqwertyuioplkjhgfdsaxcvbnmougfds

output:
asdfghjkk|kkkkkkkkkkkkkkkkkkkkjj|jjjjjjjjjuuuuuuuuuuu|uu
zxccvbnm|lkjhgfdsaqwertyuioplkj|hgfdsaxcvbnmougf|ds

what i have tried is as below:
nawk -F\n -f addDelimiter.awk src.txt >tgt.txt

##addDelimiter.awk

printf substring($1,0,9)"|"substring($1,9,20)"|"substring($1,20,20)"|"substring($1,40,2)

it is bailing out error when i ran first, checked open and close paranthesis then i ran next time length of string is too large.

as i told u earlier i took line of size 3200 chars.

please advise on above script.

thanks in advance.
--Bali

substring is not an awk function, typo?

Most awk implementations have a limitation of 3000 characters per record. Try it with gawk or mawk if you have that installed on your system.

You can use substr() instead of substring() depending on what version of awk your using. Besides gawk or mawk you may also have nawk depending on your O/S.

xx='asdfghjkkkkkkkkkkkkkkkkkkkkkkjjjjjjjjjjjuuuuuuuuuuuuu'
echo $xx | sed 's/^\(.\{9\}\)\(.\{20\}\)\(.\{20\}\)\(.\{2\}\)\(.*$\)/\1|\2|\3|\4|\5/'

output:

asdfghjkk|kkkkkkkkkkkkkkkkkkkk|jjjjjjjjjjjuuuuuuuuu|uu|uu

I think sed will have no issues for 3200 chars.
But, for 200 fields/column the command will be really huge.
Just like AWK it will have to be written to a file and invoked.

sed -f sedcomm.sed inputfile