Help for File Modification

Hi,

I have a file abcd.txt.
cat abcd.txt
output is as follows :

"aa"~"bb"~"001"~""~""~"cc"
"dd"~"005"~""
~""~"kk"~"aa"~"00

8"~""~""~

I want the output looking like:
cat abcd.txt

"aa"~"bb"~"001"~""~""~
"cc""dd"~"005"~""~""~
"kk"~"aa"~"008"~""~""~

I have a script.

echo $((`cat abcd.txt | sed 's/[^~]//g' | wc -c` - 1 ))

here I have to count ~ character. If count 5 then enter newline.
But I am not doing this. Anyone can help me please.

Thanks in advance

@mnmonu: You wanted 5 numbers of '~' on a line, right? Sample output is contradicting with your requirement.

$ perl -pe 's/\n//g' inputfile | perl -pe 's/(.+?~.+?~.+?~.+?~.+?~)/$1\n/g'
"aa"~"bb"~"001"~""~""~
"cc""dd"~"005"~""~""~"kk"~
"aa"~"008"~""~""~

@balajesuri

It's working fine. But we can't use perl. Is there any shell scripting?

$ cat inputfile | tr -d '\n' | sed 's/\([^~]*~[^~]*~[^~]*~[^~]*~[^~]*~\)/\1\n/g'
"aa"~"bb"~"001"~""~""~
"cc""dd"~"005"~""~""~"kk"~
"aa"~"008"~""~""~

If count 55 numbers of '~' on a line, then what should I do ??