I have an issue transferring files between Unix(AIX) and Windows. I use the following mount command to mount a Windows folder on Unix.

mount -v cifs -n /admin/@dmin -o file_mode=775,dir_mode=775,uid=0,gid=0 /TEST/Finance

On my Windows machine, I pick up these files on this mount directory for processing. I use IBM Connect:Direct to transfer the files.

Issue is that when moving a file from the Windows Mount on Unix to the Windows server, the CR (Carriage Return) is missing in my file and only LF (Line feed) is present, meaning that when you open with a notepad, you can see all the text one a single line.

How do I keep both the CR and LF when transferring files from Unix to Windows?

Is there something wrong with my mount command?

  • How are you transferring the files? Since you mention a CIFS mount, it looks like you copy the files on AIX, which you could do with a file manager or the cp command. But below, you said something about a file transfer application with text mode. That sounds like FTP, but in that case you wouldn’t need to mount the CIFS drive at all. – yellowantphil Apr 29 '15 at 13:53

I don't think this likely has anything to do with the mounting. Are you sure the CR characters are there originally in the file? Assuming they are not, you can use unix2dos to add them, though I haven't actually verified that exists for AIX. You could use sed like

sed -i -e 's/\n/\r\n/g' <file>

if you don't have unix2dos available. The -i flag tells sed to modify the file in place--normally it will print the results to stdout. You can have any number of -e flags which tell sed to perform some actions. In this case we are using the action s to substitute values. The / serves as the delimiter for the substitution command. The first part, \n, is the pattern we are looking for, and the second part, \r\n, is the pattern to replace it with. The final g tells sed to match it everywhere it's seen, not just the first place per line (though this probably doesn't matter much when matching the end of a line).

| improve this answer | |
  • Thank you very much for your comment. What is sed and what is it used for? – DextrousDave Apr 29 '15 at 13:37
  • sed is a common unix tool that will modify streams, as I'll modify my answer to explain better how I'm using it – Eric Renouf Apr 29 '15 at 13:38

It doesn’t matter how you mounted the partition. Every byte of every file will be transferred. If your files do not have carriage returns after the transfer, then they didn’t have them before. I don’t know what command to run on AIX to check the encoding of your files, but you could just look at them in a binary editor and see if the lines are terminated with LF or CRLF.

If you want to copy text files from UNIX to Windows and have the newlines converted to CRLF, you could use ftp in ASCII mode. I think serial connections can do newline conversion too. I’m not aware of any other protocols that attempt to convert text in transit, although there might be some.

You could also convert all of your files before or after transferring, or use an editor on Windows that understands UNIX newlines.

| improve this answer | |
  • Thank you. Good explanation. My File Transfer application has Text and Binary transfer modes. I assume Text is ASCII? I tried using both the text and binary modes with no luck of adding the CR – DextrousDave Apr 29 '15 at 13:38
  • @DextrousDave What application is it? Text is ASCII, yes. If you transfer a text file with LF newlines from AIX to Windows, then text transfer mode should add the carriage returns. If it doesn’t, I don’t know why not. – yellowantphil Apr 29 '15 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.