LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 09-05-2013, 07:02 PM   #1
andrew777
LQ Newbie
 
Registered: Feb 2009
Posts: 14

Rep: Reputation: 0
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

Last edited by andrew777; 09-05-2013 at 07:06 PM.
 
Old 09-05-2013, 08:40 PM   #2
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,624

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
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"
 
Old 09-05-2013, 08:54 PM   #3
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
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
 
1 members found this post helpful.
Old 09-05-2013, 11:17 PM   #4
andrew777
LQ Newbie
 
Registered: Feb 2009
Posts: 14

Original Poster
Rep: Reputation: 0
Thank you Firerat, the -i option will help me a lot.
 
Old 09-06-2013, 12:10 AM   #5
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Closing write end of a pipe does not seem to cause EOF to appear on read end... Kurt M. Weber Programming 2 04-01-2013 12:28 AM
question about text/source files: what is the EOF indicator? rahul8705 Linux - General 2 11-10-2010 11:36 AM
How do I remove everything after a certain character in text files? SentralOrigin Linux - General 3 01-14-2009 02:15 PM
remove the 'd' character from the end of string powah Programming 6 11-08-2007 07:00 AM
EOF character for Mandrake 10? ThePenguin Programming 2 09-05-2004 02:39 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 04:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration