Is there a command to remove square symbol (EOL) from a text file?

I have an import file with a square symbol right at the end. Now from looking at posts on the net, this would appear to be an EOL or in this case EOF marker. I also think the file is from Unix.

Is there a command that I could perhaps put into a batch file to remove this symbol from text files in a given location?
richardrayAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JCinDECommented:
EOF is not a character in a file. It is a logical marker indicating no more data exists.

What you are seeing is a linefeed character. DOS/Windows use a combination of carriage return (ASCII 13) and linefeed (ASCII 10) to mark the end of a line. UNIX/Linux use just a carriage return. Windows sees the carriage return character by itself and does not correctly identify it as end of line. In fact, Windows does not know how to display it at all, so it uses the black box to represent it.

Many text editors can automatically convert UNIX end of line markers to Windows end of line markers and display the file correctly. If you want to do it yourself, simply insert an ASCII 10 character right after every ASCII 13 character in the file.
SweetsGreenCommented:
http://www.textpad.com/

textpad can read/write both windows and unix files (and mac).

opening the file and changing the format to PC when saving should do the trick.

reedsrCommented:
use unix2dos  it is free ware and shoudl do the trick

http://home.clear.net.nz/pages/niche/unix2dos-download.html
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

Jaime OlivaresSoftware ArchitectCommented:
If fact there is a EOF character for text files, at least in old DOS, it is ASCII 26.
I have seen it many times, even some old DOS text editors put an EOF char at the end of file. If you use DOS 'TYPE' command, it will show you file contents just up to EOF character is found.
Diego PazosCommented:
To convert a file to DOS format, first open it with the DOS text editor.
To do so, open the DOS editor, open a command prompt window, use the CD command to change to the directory where the file resides and type 'EDIT filename'.
Once inside the editor, just save it and quit.
The file will be converted to DOS format (the one Notepad, among others, uses).
nayernaguibCommented:
You can use a hexadecimal editor to replace every occurence of LF (Line Feed, hexadecimal code 0A), with the two characters CR/LF (hexadecimal code 0D0A).

_______________

  Nayer Naguib
Diego PazosCommented:
> You can use a hexadecimal editor to replace every occurence of LF (Line Feed, hexadecimal code 0A), with the two
> characters CR/LF (hexadecimal code 0D0A).

Now that's what I call overcomplicating. :D
nayernaguibCommented:
uKER, I don't know about your education, but what you think is "overcomplicating" doesn't seem so for others.

Also, I've gained in 4 months 43 points more than 4 times the expert points you have gained in 2 years (!!), so it would be better that you leave the decision to the author.

_______________

  Nayer Naguib
Jaime OlivaresSoftware ArchitectCommented:
>I have an import file with a square symbol right at the end
I think author is refering at the **end of file** not at the **end of each line**
But we have to what him to answer.....
sriramiyerCommented:
The JGsoft EditPad Pro is a powerful and versatile text editor or word processor for all windows, UNIX and Macintosh files

Try Free Evaluation from the following URL:

http://www.editpadpro.com/download.html

In this editor, use menu options,

convert -> To Windows (CR LF)
convert -> To UNIX (LF only)
convert -> To Macintosh (CR only)

I think this will serve the purpose.

regards

Sriramiyer


billtouchCommented:
The question I haven't seen asked yet is: Are you looking to do this manually each time - load the file into an editor - remove the offending character(s) - rewrite the file? Or are you looking for an automated solution that you run and it 'takes care of things'?

What OS are you recieving this file on and what os is sending it? Do you have a development environment on the recieving computer?

Bill
richardrayAuthor Commented:
Sending on Unix, receiving in Windows. File is a txt and has the square at the end of the file only. Need to remove this to import into a third party system which rejects the character.

Automatically in a batch file that can be scheduled when the file is received would be best.

Thanks!
billtouchCommented:
That character you are trying to get rid of is a Ctl-Z (0x1A). It is an old DOS end of file marker as jaime_olivares said.

The simplest way to get rid of it is to copy the file dropping the last character.

int main ()
{
   FILE *infile;
   FILE *outfile;
   int c;

   infile = fopen( "File1.txt", "r" );
   outfile = fopen( "File2.txt", "w" );
   while ( (c = getc(infile)) != EOF ) {
   if ( c != 0x1a )
      putc( c, outfile );
   };
   fclose( infile );
   fclose( outfile );
}

That should do it for you. If you can't compile it under windows, run it on the Unix machine then send it to Windows.

Bill
Jaime OlivaresSoftware ArchitectCommented:
I have just found this old and nice DOS program: filter.exe at http://riverbbs.net/pub3/bfds/FILTER.ZIP

It will do lots of filter operations on text files, to remove EOF characters just need:

filter <infilename.txt >outfilename.txt

Also you can trip some lines, remove CR or LF characters, etc.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
richardrayAuthor Commented:
A very BIG thankyou to everyone's comments so far. I will be trying them tomorrow and let you know if I require further assistance!!
richardrayAuthor Commented:
Thanks jaime_olivares  - this worked great!

Thanks everyone else also for your time and effort!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.