dos2unix命令 [英] dos2unix command
本文介绍了dos2unix命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个脚本
#!/bin/sh
for i in `ls -R`
do
echo "Changing $i"
fromdos $i
done
我想从更多子目录中的许多文件中删除"^ M"字符.我知道了:
I want to remove "^M" charcaters from many files which are in more subdirectories. I got this:
fromdos: Unable to access file
我有什么想念的吗?
提前谢谢.
推荐答案
我想您不需要 for 循环.
这是扩展名为".ext"的文件的解决方案的快速概览(此类命令应具有限制性)
Here is a quick panorama of solutions for files with extension ".ext" (such commands shall be somehow restrictive)
注意:^ M是通过CTRL-V"+" CTRL-M获得的
note : ^M is obtained with CTRL-V" + "CTRL-M"
# PORTABLE SOLUTION
find /home -type f -name "*.ext" -exec sed -i -e 's/^M$//' {} \;
# GNU-sed
find /home -type f -name "*.ext" -exec sed -i -e "s/\x0D$//g" {} \;
# SED with more recent nux
find /home -type f -name "*.ext" -exec sed -i -e "s/\r$//g" {} \;
# DOS2UNIX
find /home -type f -name "*.ext" -print0 | while read -r -d "$(printf "\000")" -r path; do dos2unix $path $path"_new"; done
# AWK
find /home -type f -name "*.ext" -print0 | while read -r -d "$(printf "\000")" -r path; do awk '{ sub("\r$", ""); print }' $path > $path"_new"; done
# TR
find /home -type f -name "*.ext" -print0 | while read -r -d "$(printf "\000")" -r path; do cat $path | tr -d '\r' > $path"_new"; done
# PERL
find /home -type f -name "*.ext" -exec perl -pi -e 's/\r//g' {} \;
这篇关于dos2unix命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文