Find field count and replace

Hello All,

I have a file with contents like

apple|ball|charlie|David|
England|France|Germany|
Ireland|Japan|King|London|
Man|Nancy|Orange|

here the column delimiter is |

so if any of the lines/rows in the file has 3 only records (last field is empty), i want to place a | at the end of the row/line, so the output should be like

apple|ball|charlie|David|
England|France|Germany||
Ireland|Japan|King|London|
Man|Nancy|Orange||

if NF=3 place | at the end.

Appreciate your help. Thanks

 
awk -F| ' if(NF==3){print $0"|"} else {print $0}' inputfile

if you have Ruby(1.9+)

$ ruby -pne '$_=$_.chomp+"|\n" if $_.count("|")<4;' file
awk -F'|' 'NF==4{$0=$0 FS};1' yourFile

Thank you Guys

awk -F'|' 'NF==4{$0=$0 FS};1' yourFile .... worked
awk -F| ' if(NF==3){print $0"|"} else {print $0}' inputfile ..throwed syntax error on Aix

awk -F"|" 'if(NF==3) {print $0}"|" ; else {print $0}' 1.sql
Syntax Error The source line is 1.
The error context is
>>> if <<< (NF==3) {print $0}"|" ; else {print $0}
awk: 0602-500 Quitting The source line is 1.

enclosed if and else in {}, but the out put was not the desired.

anyway the first one worked ..thank you!