Insert character in a specific position of a file

Hi,

I need to add Pipe (|) at 5th and 18th position of all records a file. How can I do this?
I tried to add it at 5th position using the below code. It didnt work. Please help!!!

awk '{substr($0,5,1) ~ /|/}{print}' $input_file > $temp_file
sed 's/\(.\{5\}\)/&|/;s/\(.\{19\}\)/&|/' $input_file > $temp_file