Strange behavior on one of my server

I am not sure what is wrong, but I have some strange behavior when printing things out.

I do create a file with only one word test , no space, no new line etc.

nano file<enter>
test<ctrl x>y<enter>

Server 1 gets (fail)

awk '{print "+"$0"*"}' file
*test

Server 2 gets (OK)

awk '{print "+"$0"*"}' t
+test*

What is going on with my Server1?

Hi,
Could you dump your file with od -c command ?
I expect your file on server that fail content a '\r':

$ od -c t
0000000   t   e   s   t  \n
0000005
$ awk '{print "+"$0"*"}' t
+test*
$ od -c t
0000000   t   e   s   t  \r  \n
0000006
$ awk '{print "+"$0"*"}' t
*test

Regards.

You are correctly. :slight_smile:
Why does one server add the \r but not the other.
I do the same on both server, using nano to create a file.
When I do test again, I am not able to reproduce the problem.

Might you have uploaded the 'test' file from a windows machine at one point? That would create it as a Windows text file with carriage returns.

Or, do you have different configuration files on the two servers?

What type of configuration files?
File is not uploaded, its created using nano via SSH

Not sure. Sth like .nanorc in /etc or in your home directory?

It's possible to create a \r inside nano with the right key sequence but I can't remember what it is. I can't find any commandline switch or nano option which forces dos-mode though.

nano always adds a newline, always.

What is OS ?
MAC ==> end line is \r
DOS ==> end line is \r\n
Unix ==> end line is \n

Maybe, when you edit your file with problem, the file already exist and this content was just one byte ==> \r
And if force convert unix mode is not enable in nano...

Regards.

Server 1 Ubuntu 12.04.3 LTS

Server 2 Ubuntu 12.04.2 LTS

File was created with exact same keystroke.

But for some reason I am not able to recreate the error.
So I have learned a new command to test the file if some is wrong next time od -c