查找并删除在Ubuntu DOS行结束 [英] Find and remove DOS line endings on Ubuntu

查看:124
本文介绍了查找并删除在Ubuntu DOS行结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现我的很多文件具有DOS行结束。在六,他们看起来是这样的:^ M。
我不想修改没有这些DOS行结尾的文件。我如何做到这一点使用bash脚本?谢谢!

EV


解决方案

 的grep -url ^ M。 | xargs的fromdos

的grep让你有DOS行结束当前目录下的所有文件的清单。

-U 使得grep的考虑行结尾,而不是默认剥夺他们带走

-R 使得递归

-l <​​/ code>使它只列出文件名,而不是匹配的行

那么你的管道,列出入转炉命令(即 fromdos 在Ubuntu上, DOS2UNIX的我在哪里来自)。

注意:不实际键入 ^ M 。相反,你需要preSS &LT;按Ctrl-V&GT; 然后&LT;按Ctrl-M&GT; 插入 ^ M 字符,让grep的了解你要什么。或者,你可以代替键入 $'\\ r' ^ M (但我认为这可能只是工作对于bash ...)。

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 I do this using a bash script? Thanks!

EV

解决方案

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 <Ctrl-V> then <Ctrl-M> 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...).

这篇关于查找并删除在Ubuntu DOS行结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆