Insert | in specific position

Hi ,

I have a file which has line similar to below

13123324234234234234234234234234234
3454546456dfhgfhgh454645654asdasfsdsddfgdgdfg
345345345mnmnbmnb346mnb4565464564564645645

Not for each line for specific position I need to insert some '|'

Positions are fixed. Like 3,5,9,11
So the above file will be after the parsing

131|23|3242|34|234234234234234234234234
345|45|4645|6d|fhgfhgh454645654asdasfsdsddfgdgdfg
345|34|5345|mn|mnbmnb346mnb4565464564564645645

Please help on how I can do this.

use below code

sed "s/^\(...\)\(...\)\(...\)\(.*\)/\1|\2|\3|\4/g" $file

[/SIZE][/FONT]

This doesn't give the desired output. Some changes make it work:

# sed "s/^\(.\{3\}\)\(.\{2\}\)\(.\{4\}\)\(.\{2\}\)\(.*\)/\1|\2|\3|\4|\5/g" anup.txt 
131|23|3242|34|234234234234234234234234
345|45|4645|6d|fhgfhgh454645654asdasfsdsddfgdgdfg
345|34|5345|mn|mnbmnb346mnb4565464564564645645
1 Like

Bob's code is correct. I didnt realize that there are 2 and 4 characters. I thought that all the 3 character separations.

Thanks Bob

awk '{ print substr($0,1,3),substr($0,4,2),substr($0,6,4),substr($0,10,2),substr($0,12); }' OFS=\| file
1 Like

thank you all..

I already was trying and found my code is almost similar to what bipinajith posted.