Solved

Blank Line when taking a file from Unix to windows box

Posted on 2010-09-21
13
457 Views
Last Modified: 2012-05-10
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
0
Comment
Question by:suhinrasheed
  • 4
  • 4
  • 3
  • +1
13 Comments
 
LVL 16

Expert Comment

by:Bryan Butler
ID: 33728137
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
 

Author Comment

by:suhinrasheed
ID: 33728269
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
 
LVL 16

Expert Comment

by:Bryan Butler
ID: 33728452
Basically it will be ignored by VI/unix, whereas it will be interpreted as a line feed on windows.
0
 
LVL 34

Expert Comment

by:Duncan Roe
ID: 33729955
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
 
LVL 34

Expert Comment

by:Duncan Roe
ID: 33729961
I meant Lf (\n) - just a typo
0
 

Author Comment

by:suhinrasheed
ID: 33730929
So what is the method I can avoid the Blank line in the binary format file I move from Unix to windows box
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Expert Comment

by:sage444
ID: 33732645
hello
just try to trim last byte from file before copy to windows box

head -c <sizeOfFile-1> filename > newfilename
0
 
LVL 34

Expert Comment

by:Duncan Roe
ID: 33733002
Or (easier)

head -c -1 filename > newfilename
0
 

Author Comment

by:suhinrasheed
ID: 33740595
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
 
LVL 1

Expert Comment

by:sage444
ID: 33740912
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
 
LVL 34

Accepted Solution

by:
Duncan Roe earned 500 total points
ID: 33742768
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
 
LVL 16

Expert Comment

by:Bryan Butler
ID: 33746701
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
 
LVL 16

Expert Comment

by:Bryan Butler
ID: 33746722
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

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now