Delete last character in dos file

Hi,

I am creating a file using an unix script and then converting it to dos format. After conversion a ^Z character is added at the end of file. I want remove this last ^Z character. Can anyone please tell me how to do this?

Thanks a lot.

Sunil

if you need not to convert file to dos format, commend that line in the script

You can remove the ^Z with sed as follow:

sed 's/^Z//' file

To get ^Z type Ctrl-v and Ctrl-z.

Regards

Hi,

I have NULL characters at the beginning of each line in the file which are necessary as i have to process this file later.

I used the sed command suggested above. It removes the last ^Z. It also removes NULL characters present at the beginning of each line in my file.(This is a dos file that i am processing)

Are you using

dos2unix

command for conversion of dos file to unix format?
if you are moving your file from dos environment to unix the run

dos2unix filename

if unix to dos then

unix2dos filename

after this process the file.

Hi Franklin52,

I have tried to remove the ^Z at the end of the file as recommended by you sed 's/^Z//' file but the ^Z still exists any help.

TQ

Have you typed Ctrl-v and Ctrl-z as I mentioned before?

Regards

Yes, i have found the below one in same site and it worked. Thanks for your prompt reply,

sed '/^Z/d' myorginalfile>newfile