UNIX file handling issue

I have a huge file semicolon( ; ) separated records are Pipe(|) delimited.

e.g

abc;def;ghi|jkl;mno;pqr|123;456;789

I need to replace the 50th field(semicolon separated) of each record with 9006. The 50th field can have no value e.g. ;;

Can someone help me with the appropriate command.

I haven't tried it but you can try it :

awk -F";" '{$50=9006}1' RS="|" OFS=";" ORS="|" yourfile
awk -F";" '{for(i=1;i<=NF;i++){if(!(i%50)){$i=9006}}}1' OFS=";" RS=ORS="|" yourfile

Thanks for the code. But I am getting error on UNIX.

fwtwc@meraqapp01:/openet/u0002/test_files$ awk -F";" '{for(i=1;i<=NF;i++){if(!(i%50)){$i=9006}}}1' OFS=";" RS=ORS="|" newfile.dat
awk: syntax error near line 1
awk: bailing out near line 1

what can be a possible reason. Even tried running

#!/bin/awk -f

before the command

---------- Post updated at 01:26 AM ---------- Previous update was at 01:00 AM ----------

nawk worked for me instead of awk.

But another issue came in some records are of less than 50 in lengths also if the record is not present at all like "||" then the data is getting populated as
|;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;9006|

|1000;2012-08-20 00:22:55;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;9006|

I dont want any data inside two Pipe separated records. Or if the number of ';' separated fields is less than 50

Try to extend ctsgnb's code like

awk -F";" 'NF>=50{$50=9006}1' RS="|" OFS=";" ORS="|" yourfile