Splitting single row into multiple rows based on for every 10 digits of last field of the row

Hi ALL,
We have requirement in a file, i have multiple rows.

Example below:

Input file rows

01,1,102319,0,0,70,26,U,1,331,000000113200000011920000001212
01,1,102319,0,1,80,20,U,1,241,00000059420000006021

I need my output file should be as mentioned below. Last field should split for every 10 digits.

Output file rows

01,1,102319,0,0,70,26,U,1,331,0000001132
01,1,102319,0,0,70,26,U,1,331,0000001192
01,1,102319,0,0,70,26,U,1,331,0000001212 
01,1,102319,0,1,80,20,U,1,241,0000005942 
01,1,102319,0,1,80,20,U,1,241,0000006021

Can you please share me code how we can achive this thru unix

Thanks,
Kalyan

What operating system and shell are you using?

What have you tried to solve this problem on your own?

Hi,
We are using AIX and shell is KSH.

Thanks,
Kalyan.

It always helps if you show us what you have tried on your own so we have a better understanding of what you're trying to do and what kind of help you need. The following awk script seems to do what you want (but it doesn't add a space to the end of the 3rd and 4th rows of your output that you included in the output you said you want):

awk '
BEGIN {	FS = OFS = ","
}
{	d = $NF
	for(i = 1; i <= length(d); i += 10) {
		$NF = substr(d, i, 10)
		print
	}
}' Input

which, if the file named Input contains the example input rows you provided, produces the output:

01,1,102319,0,0,70,26,U,1,331,0000001132
01,1,102319,0,0,70,26,U,1,331,0000001192
01,1,102319,0,0,70,26,U,1,331,0000001212
01,1,102319,0,1,80,20,U,1,241,0000005942
01,1,102319,0,1,80,20,U,1,241,0000006021

If someone else wants to try this on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk or nawk .

Thanks lot Don. It is working for me... now.