返回信息流能用C#将DOS格式的文件转化为Unix格式的文件么?
这是一条镜像帖。来源:北邮人论坛 / dot-net / #3258同步于 2011/8/18
该镜像源已超过 30 天没有更新,可能在源站已被删除。
dotNET机器人发帖
DOS格式文件转化为Unix格式文件
lzc86
2011/8/18镜像同步6 回复
订阅后,新回复会通过你的通知中心匿名送达。
6 条回复
【 在 ahomer 的大作中提到: 】
: 简单直接用Notepad++之类的编辑工具替换不行,
: DOS文本转换到Unix文本,把换行符从\n\r替换成\n就行了吧
: --
: ...................
问题是有800多个文件需要这么处理。
如果只是处理换行的话,很容易的
之前用过一个linux的命令叫做dos2unix可以直接将相应的换行处理掉
至于怎样处理800多个文件,也不困难,如果这个命令不支持一次指定多个文件,那就在外边把命令编辑好,然后粘到linux终端或者保存成脚本运行
【 在 lzc86 的大作中提到: 】
: 问题是有800多个文件需要这么处理。
re~
不知这样是否OK?
dos2unix `ls`
我试过3个文件没有问题:
[root@localhost test]# ll
total 12
-rw-r--r-- 1 root root 2 Aug 18 21:53 1.txt
-rw-r--r-- 1 root root 2 Aug 18 21:53 2.txt
-rw-r--r-- 1 root root 2 Aug 18 21:53 3.txt
[root@localhost test]# dos2unix `ls`
dos2unix: converting file 1.txt to UNIX format ...
dos2unix: converting file 2.txt to UNIX format ...
dos2unix: converting file 3.txt to UNIX format ...
[root@localhost test]#
如果不行,脚本这样写:
#!/bin/bash
echo Note:
echo You need to run this script in the folder containing your files to convert
for files in `ls`
do
dos2unix $files
done
运行结果:
[root@localhost test]# ll
total 20
-rw-r--r-- 1 root root 2 Aug 18 21:59 1.txt
-rw-r--r-- 1 root root 2 Aug 18 21:59 2.txt
-rw-r--r-- 1 root root 2 Aug 18 21:59 3.txt
-rw-r--r-- 1 root root 2 Aug 18 21:59 4 name.txt
-rwxr-xr-x 1 root root 147 Aug 18 21:59 convert.sh
[root@localhost test]# rm 4\ name.txt
rm: remove regular file `4 name.txt'? y
[root@localhost test]# ll
total 16
-rw-r--r-- 1 root root 2 Aug 18 21:59 1.txt
-rw-r--r-- 1 root root 2 Aug 18 21:59 2.txt
-rw-r--r-- 1 root root 2 Aug 18 21:59 3.txt
-rwxr-xr-x 1 root root 147 Aug 18 21:59 convert.sh
[root@localhost test]# chmod +x convert.sh
[root@localhost test]# ./convert.sh
Note:
You need to run this script in the folder containing your files to convert
dos2unix: converting file 1.txt to UNIX format ...
dos2unix: converting file 2.txt to UNIX format ...
dos2unix: converting file 3.txt to UNIX format ...
dos2unix: converting file convert.sh to UNIX format ...
[root@localhost test]#
其实太silly了这个脚本。
ps:如果你的文件名有空格就不好弄了,需要重新用别的方法来遍历所有文件名,或者你手动把文件名中的空格给删除了。
【 在 hobby 的大作中提到: 】
: 如果只是处理换行的话,很容易的
: 之前用过一个linux的命令叫做dos2unix可以直接将相应的换行处理掉
: 至于怎样处理800多个文件,也不困难,如果这个命令不支持一次指定多个文件,那就在外边把命令编辑好,然后粘到linux终端或者保存成脚本运行
: ...................