File conversion

Hi Everyone,

Can someone plesae advise on converting the inputted file into required output? First field is L then amount will - symbol.
Sample input file

B|T|SASOFTB00016|20090330|20090330|15000|9089001
B|T|SABH00000012|20090330|20090330|7000|9089003
L|T|SABIOTN00029|20090330|20090330|250000|9089004
L|T|SABRE0000012|20090330|20090330|3000|9089005
B|T|SACRSNT00011|20090330|20090330|13000|9089006

Below is Output file and it have some hardcoded stuff at begining and in between.

851~123456~20090330~20090330~FI~15000~9089001~SASOFTB00016
851~123456~20090330~20090330~FI~7000~9089003~SABH00000012
851~123456~20090330~20090330~FI~-250000~9089004~SABIOTN00029
851~123456~20090330~20090330~FI~-3000~9089005~SABRE0000012
851~123456~20090330~20090330~FI~13000~9089006~SACRSNT00011

I have tried converting the file with awk but got below error.

awk -F "|" 'BEGIN {OFS="~"} {print $1 $2} '  inputfile
awk: syntax error near line 1
awk: bailing out near line 1

Can someone please advise?

Cheers,
gehlnar

I don't understand how you derive the '50000' and the '3000' bolded numbers...

vgersh,

I think validation of B and L , i will do using shell and I was not sure about the rest of the things..I have corrected the Output and there was slight mistake in output.

Cheers,
gehlnar

nawk -F'|' '
   BEGIN {
     OFS="~"
     PREFIX="851~123456"
   }
   { print PREFIX,$4,$5,"FI",($1=="L")?0-$6:$6,$NF,$3}' myFile

Vgersh,

Ur solution was really helpful... thank you very much.

Cheers,
gehlnar