LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   How can I remove ^@ (Windows EOF character) from the end of text files (https://www.linuxquestions.org/questions/linux-general-1/how-can-i-remove-%5E%40-windows-eof-character-from-the-end-of-text-files-4175476093/)

andrew777 09-05-2013 07:02 PM

How can I remove ^@ (Windows EOF character) from the end of text files
 
Hi,

I generated a couple of thousand xml files which contain site maps. These files were generated in Windows and therefore have a special character at the end of the file to indicate the end of the file. When I upload these to Linux I get an ^@ character on the last line of the file which generates an error message when the xml sitemap file is read. So I need to remove this special character. I can edit each file manually with vi and remove the character but it will take me forever.

Is there a way to remove this character from each of the thousand files using a command line function?

Any help would be appreciated.
Thanks

========================

Just found the answer in my own notes (using sed)!
Sometimes it helps to explain the problem, just to get your mind to work. :-)

sed 's/\c@//' sitemap_001.xml > sitemap_001.modified

John VV 09-05-2013 08:40 PM

there is or should be two utility's installed called "dos2unix" and "unix2dos"
run "dos2unix" on the file

also most text editors have an option to remove the "Microsoft End of line"

Firerat 09-05-2013 08:54 PM

if you add -i to your sed, no need for intermediate "modified" file

e.g.

Code:

sed -i 's/\c@//' sitemap_*.xml
will do 'the lot'


ref dos2unix, unix2dos
if not already installed, and you have busybox installed you could use it's version

Code:

busybox dos2unix sitemap_*.xml

andrew777 09-05-2013 11:17 PM

Thank you Firerat, the -i option will help me a lot.

Firerat 09-06-2013 12:10 AM

I should have mentioned this earlier.

you can add a suffix to the -i ( e.g. -i.backup ) which will result in a copy of the original being saved to a suffixed file

sitemap_001.xml gives you a modified sitemap_001.xml and the original as sitemap_001.xml.backup


All times are GMT -5. The time now is 03:17 AM.