如何在Unix行尾(CR/LF到LF)中转换Windows行尾 [英] How to convert Windows end of line in Unix end of line (CR/LF to LF)

查看:667
本文介绍了如何在Unix行尾(CR/LF到LF)中转换Windows行尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Java开发人员,正在使用Ubuntu进行开发.该项目是使用Eclipse在Windows中创建的,并且使用的是CP1252编码.

I'm a Java developer and I'm using Ubuntu to develop. The project was created in Windows with Eclipse and it's using the CP1252 encoding.

要转换为UTF-8,我使用了重新编码程序:

To convert to UTF-8 I've used the recode program:

find Web -iname \*.java | xargs recode CP1252...UTF-8

此命令给出此错误:

recode: Web/src/br/cits/projeto/geral/presentation/GravacaoMessageHelper.java failed: Ambiguous output in step `CR-LF..data

我已经设法解决这个问题,并在此处获取解决方案: http://fvue.nl/wiki/Bash_and_Windows#Recode:_Ambiguous_output_in_step_.60data..CR-LF.27 并说:

I've serached about it and get the solution here: http://fvue.nl/wiki/Bash_and_Windows#Recode:_Ambiguous_output_in_step_.60data..CR-LF.27 and it says:

将行尾从CR/LF转换为a 单个LF:使用vim编辑文件, 给出命令:set ff = unix并保存 文件.现在重新编码应该运行 没有错误.

Convert line endings from CR/LF to a single LF: Edit the file with vim , give the command :set ff=unix and save the file. Recode now should run without errors.

很好,但是我有很多文件要删除CR/LF字符,我无法打开每个文件来执行此操作. Vi不提供任何用于bash操作的命令行选项.

Nice but I've many files to remove the CR/LF character, I can't open each to do it. Vi doesn't provide any option to command line for bash operations.

sed吗?怎么样?

感谢=)

推荐答案

应该有一个名为dos2unix的程序,它将为您修复行尾.如果尚未在Linux机器上安装它,则应该可以通过软件包管理器使用它.

There should be a program called dos2unix that will fix line endings for you. If it's not already on your Linux box, it should be available via the package manager.

这篇关于如何在Unix行尾(CR/LF到LF)中转换Windows行尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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