Remove Last field from a delimited file

Hi,

I have a '~' delimited file and i want to remove the last field using awk. Please find the sample records below:

1428128~1~0~1100426~003~50220~005~14~0~194801~11~0~3~14~0~50419052335~0~0820652001~2~00653862 ~0~1~0~00126~1~20000110~20110423~R~          ~0~Z~1662.94~ ~002041~0045~Z~
1428128~1~0~1100426~003~50220~005~14~0~194801~11~0~3~14~0~50419052335~0~0820652001~2~00653862 ~0~1~0~00126~1~20000110~20110521~R~          ~0~Z~3039.46~ ~002041~0045~Z~
1428128~1~0~1100426~003~50220~005~14~0~194801~11~0~3~30~0~50419052335~0~0820652001~2~00653862 ~0~1~0~00126~1~20000110~20110623~R~          ~0~Z~3039.46~ ~002041~0045~Z~

And also after removing the last field i want the last '~' associated with the last field to be removed for each line.

Any help appreciated...

Thanks,

Arun

Try:

awk 'sub(/~[^~]+~$/,"")' file

Hello,

Following may help too in same.

awk -F"\~" 'gsub(/.*/,X,$(NF-1)) gsub(/\~\~$/,Y) 1' OFS="~" remove_last_char_file12113

Output will be as follows.

1428128~1~0~1100426~003~50220~005~14~0~194801~11~0~3~14~0~50419052335~0~0820652001~2~00653862 ~0~1~0~00126~1~20000110~20110423~R~ ~0~Z~1662.94~ ~002041~0045
1428128~1~0~1100426~003~50220~005~14~0~194801~11~0~3~14~0~50419052335~0~0820652001~2~00653862 ~0~1~0~00126~1~20000110~20110521~R~ ~0~Z~3039.46~ ~002041~0045
1428128~1~0~1100426~003~50220~005~14~0~194801~11~0~3~30~0~50419052335~0~0820652001~2~00653862 ~0~1~0~00126~1~20000110~20110623~R~ ~0~Z~3039.46~ ~002041~0045

Thanks,
R. Singh

Hi, please provide a sample output, rather than a colloquial description..