Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm on Debian Jessie. When I open a new textfile with mousepad and save it, then modify it with vim and save it again, I cannot print or grep the contents of it anymore.

If I do cat file, nothing is shown in the terminal. If I open file with vim or mousepad, I see the contents. If I write the file with vim, the following is shown in the status line:

"file" [mac] 2L, 5C written

While for a "normal" file, I only get

"file" 2L, 5C written

I thought the [mac] had something to do with the formatting of the new lines, so I tried to run:

dos2unix file

but the problem persists. Does anyone know what exactly is wrong with the file?

share|improve this question
2  
vim actually has a built-in option for this. Simply run :set ff=unix to convert the file you are currently editing to use LF-only line endings. Then, overwrite the file with :w. –  HalosGhost Jul 12 at 11:25
add comment

1 Answer 1

up vote 7 down vote accepted

Use recode, e.g.: recode /cr file

Note: the fact that you can see the contents in the terminal with cat file is that the Mac end-of-line is CR, which puts the cursor at the beginning of the line without going to the next line, so that everything gets overwritten.

share|improve this answer
1  
I'm wondering why the OP had the pre OSX old Mac CR format in the first place given that he's on Debian; a misconfiguration of mousepad perhaps? –  Nick Jul 12 at 15:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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