gpt4 book ai didi

batch-file - 批处理文件 + 将 LF 转换为 CR+LF

转载 作者:行者123 更新时间:2023-12-03 23:44:26 27 4
gpt4 key购买 nike

我们有一个名为 LineFeed.sh 的 shell 脚本文件它执行将换行符( LF )转换为回车+换行符的功能。我们希望通过 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

最佳答案

您可以在 this Wikipedia page 上找到一种方法:

TYPE unix_file | FIND "" /V > dos_file

请记住,您无法将输出重定向到您正在读取的同一文件。这几乎适用于所有系统和 shell ,因此需要额外的重命名。

这里的关键是 type知道如何阅读 LF 行尾和 find然后将它们转换为 CRLF。 type单独不会对输出做任何事情(它应该这样做,因为拥有一个简单地转储弄乱它们的文件内容的命令是不好的:-))。

关于batch-file - 批处理文件 + 将 LF 转换为 CR+LF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3110031/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com