How to find out line-endings in a text file?

前端 未结 11 1059
一向
一向 2020-11-28 00:15

I\'m trying to use something in bash to show me the line endings in a file printed rather than interpreted. The file is a dump from SSIS/SQL Server being read in by a Linux

11条回答
  •  盖世英雄少女心
    2020-11-28 00:57

    Vim - always show Windows newlines as ^M

    If you prefer to always see the Windows newlines in vim render as ^M, you can add this line to your .vimrc:

    set ffs=unix
    

    This will make vim interpret every file you open as a unix file. Since unix files have \n as the newline character, a windows file with a newline character of \r\n will still render properly (thanks to the \n) but will have ^M at the end of the file (which is how vim renders the \r character).


    Vim - sometimes show Windows newlines

    If you'd prefer just to set it on a per-file basis, you can use :e ++ff=unix when editing a given file.


    Vim - always show filetype (unix vs dos)

    If you want the bottom line of vim to always display what filetype you're editing (and you didn't force set the filetype to unix) you can add to your statusline with
    set statusline+=\ %{&fileencoding?&fileencoding:&encoding}.

    My full statusline is provided below. Just add it to your .vimrc.

    " Make statusline stay, otherwise alerts will hide it
    set laststatus=2
    set statusline=
    set statusline+=%#PmenuSel#
    set statusline+=%#LineNr#
    " This says 'show filename and parent dir'
    set statusline+=%{expand('%:p:h:t')}/%t
    " This says 'show filename as would be read from the cwd'
    " set statusline+=\ %f
    set statusline+=%m\
    set statusline+=%=
    set statusline+=%#CursorColumn#
    set statusline+=\ %y
    set statusline+=\ %{&fileencoding?&fileencoding:&encoding}
    set statusline+=\[%{&fileformat}\]
    set statusline+=\ %p%%
    set statusline+=\ %l:%c
    set statusline+=\ 
    

    It'll render like

    .vim/vimrc\                                    [vim] utf-8[unix] 77% 315:6
    

    at the bottom of your file


    Vim - sometimes show filetype (unix vs dos)

    If you just want to see what type of file you have, you can use :set fileformat (this will not work if you've force set the filetype). It will return unix for unix files and dos for Windows.

提交回复
热议问题