How can I detect DOS line breaks in a file?

前端 未结 7 660
半阙折子戏
半阙折子戏 2020-12-29 09:46

I have a bunch of files. Some are Unix line endings, many are DOS. I\'d like to test each file to see if if is dos formatted, before I switch the line endings.

How

7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-29 10:30

    Using grep & bash:

    grep -c -m 1 $'\r$' file
    
    echo $'\r\n\r\n' | grep -c $'\r$'     # test
    
    echo $'\r\n\r\n' | grep -c -m 1 $'\r$'  
    

提交回复
热议问题