Blank Line when taking a file from Unix to windows box

Hi
I have file named test.msg which is generated inside a unix box.This file has some data which covers 5 lines as belo
{asdfdgdggdgfd
aghhjgjgjgjgjjjj
dgfhghghghghh
fgfgfgfhgfh45454
4545fgfgfgfgfgfgf}

If I open it in VI editor in UNIX box i see only 5 lines in the file.Now if transfer it to windows box via FTP in Binary Mode and then open the same file from an editor in windows box i.e using wordpad I can see an extra blank line i.e tota; 6 lines in the file.Even if i transfer from Unix in ASCII mode i see the same problem.
Now if you use the Textpad editor in windows I don't see it.I used another editor called Hexedit and I saw 0A hex value coming at end of the file.

I want to know what is the reason the extra blank line is coming when file is moved from Unix to Windows.If the file is Moved from Unix to Unix box also I dont see such problem

Regards,
Suhin
suhinrasheedAsked:
Who is Participating?
 
Duncan RoeSoftware DeveloperCommented:
The file in Windows will be the same binary file (unless you ftp it using ASCII mode) as it was in Linux or Unix - it's just that some editors display it differently. A program reading it with fgets() calls will see the same data under Linux / Unix or Windows.
Do you really have a problem at all?
0
 
Bryan ButlerCommented:
From wikipedia:

On Unix platforms, where C originated, the native newline sequence is ASCII LF (0x0A), so '\n' was simply defined to be that value.

See: http://en.wikipedia.org/wiki/Newline#Common_problems for details.
0
 
suhinrasheedAuthor Commented:
So are you coming to say that the source file in Unix is having the Line feed inside it already but it will never be seen using the VI editor
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Bryan ButlerCommented:
Basically it will be ignored by VI/unix, whereas it will be interpreted as a line feed on windows.
0
 
Duncan RoeSoftware DeveloperCommented:
Windows Ascii file lines end CrLf, rather than lf (\n) for Unix.
But that isn't the phenomenon you're seeing. Windows editors typically don't append the CrLf to a line until you start another line so the last line is left unterminated. If the last line does end CrLf (or just Lf) then editors show a blank line at the end of the file.
Notepad will display a file with bare Lf line endings as a single line with little square blobs for the Lf characters. Wordpad will display such a file as you would hope.
0
 
Duncan RoeSoftware DeveloperCommented:
I meant Lf (\n) - just a typo
0
 
suhinrasheedAuthor Commented:
So what is the method I can avoid the Blank line in the binary format file I move from Unix to windows box
0
 
sage444Commented:
hello
just try to trim last byte from file before copy to windows box

head -c <sizeOfFile-1> filename > newfilename
0
 
Duncan RoeSoftware DeveloperCommented:
Or (easier)

head -c -1 filename > newfilename
0
 
suhinrasheedAuthor Commented:
infact we dont want to touch the file in source box .As per the policy applicable to this file ..it has to be moved out of Unix once it is generated there to windows just like you pull a book from your bag and keep it in table...We are not even allowed to open the file before transfer in an actual scenario
0
 
sage444Commented:
Can you try this solution only one time to know right this way or not.
And if i'm right we will know what to do on the windows side
0
 
Bryan ButlerCommented:
I assume you have to use binary and you know this, but in case it helps someone, if you use text mode it will remove it.
0
 
Bryan ButlerCommented:
Your other solution is removing it using a program or script of which Duncan has a good solution there.  There's tons of others if you search for "cr lf unix windows".
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.