use*_*191 5 batch-file batch-processing
我们有一个命名的shell脚本文件LineFeed.sh,它具有将LFLinefeed ()转换为Carriage Return + LineFeed的功能.我们希望在Windows中通过批处理文件完成相同的操作.可能吗?
Linux shell文件
E_WRONGARGS=65
cat OutputList|while read -r Line
do
if [ -z "$Line" ]
then
echo "Usage: `basename $0` filename-to-convert"
exit $E_WRONGARGS
fi
NEWFILENAME=$Line.unx
CR='\015' # Carriage return.
# 015 is octal ASCII code for CR.
# Lines in a DOS text file end in CR-LF.
# Lines in a UNIX text file end in LF only.
tr -d $CR < $1 > $NEWFILENAME // here its deleting CR but i need to append LF
# Delete CR's and write to new file.
done
echo "Original DOS text file is \"$1\"."
echo "Converted UNIX text file is \"$NEWFILENAME\"."
exit 0
Run Code Online (Sandbox Code Playgroud)
Joe*_*oey 13
您可以在此维基百科页面上找到一种方法:
TYPE unix_file | FIND "" /V > dos_file
Run Code Online (Sandbox Code Playgroud)
请记住,您无法将输出重定向到您正在读取的同一文件.这几乎适用于所有系统和shell,因此需要额外的重命名.
这里的关键是type知道如何读取LF行结尾,find然后将它们转换为CRLF.type单独不会对输出做任何事情(它应该是,因为有一个命令只是转储文件内容搞乱他们是不好的:-)).
| 归档时间: |
|
| 查看次数: |
10380 次 |
| 最近记录: |