Find and remove DOS line endings on Ubuntu

前端 未结 7 1518
攒了一身酷
攒了一身酷 2021-01-04 11:37

I have found that many of my files have DOS line endings. In VI they look like this: \"^M\". I don\'t want to modify files that don\'t have these DOS line endings. How do

7条回答
  •  梦谈多话
    2021-01-04 12:19

    grep -URl ^M . | xargs fromdos
    

    grep gets you a list of all files under the current directory that have DOS line endings.

    -U makes grep consider line endings instead of stripping them away by default

    -R makes it recursive

    -l makes it list only the filenames and not the matching lines

    then you're piping that list into the converter command (which is fromdos on ubuntu, dos2unix where i come from).

    NOTE: don't actually type ^M. instead, you'll need to press then to insert the ^M character and make grep understand what you're going for. or, you could type in $'\r' in place of ^M (but i think that may only work for bash...).

提交回复
热议问题