Note : The change basically the pipe deilmited file does contain | as value for some of the column but | will come with escape char \ always when it will be a value.
Please provide your ideas. i am looking for not only awk .. something different also welcome.
Please always use code tags as per forum rules for commands.
Following may help you in same.
EDIT: Edited the post as previous post was not giving the requested output. Thank you Scrutinizer for pointing out the same.
Not a best of the solution but will provide output for input provided by the user.
awk '{gsub(/\\\|/,"#",$0);gsub(/\|/,"\"|\"");gsub(/^\"\|/,"|",$0);gsub(/$/,"\"",$0);gsub("#","|",$0); print $0}' filename
OR
awk '{gsub(/\\\|/,"#",$0);gsub(/\|/,"\"|\"");gsub(/^\"\|/,"|",$0);gsub(/$/,"\"",$0);gsub("#","|",$0)} 1' filename
@ Jotne, correct, I added a remark that my suggestion expects a leading | , like with my shell suggestion. The first is not really a field, otherwise I would expect the output to be: