请帮忙。我需要在这个Unix类的下午4点之前把它转换成。自昨晚7点以来,我一直在努力。没睡过。这个任务有三部分。我只需要最后一部分的帮助。如果我不能完成这个,我就会失败。将该文件中的CR/LF行结束符转换为Unix样式的LF行结束符?
阶段3
在同一目录中,写一个脚本asciiFix.sh这需要通过命令行的文件路径的任意数量,并且执行对每一个相同的分析。如果一个文件不是Windows ASCII,你的脚本不应该对它做任何事情。对于在Windows ASCII的每个文件,脚本应该打印消息
转换文件名
,并应然后转换CR/LF行终止在该文件中,以Unix风格的LF行终止。
例如:
cp ~cs252/Assignments/ftpAsst/d3.dat wintest.txt
./asciiFix.sh /usr/share/dict/words wintest.txt fileType.sh
converting wintest.txt
and, after the script has finished, you should be able to determine that wintest.txt is now a Unix ASCII file.
当你认为你有你的脚本工作,运行
〜cs252 /斌/ scriptAsst.pl 如果所有三个脚本工作正常,您将收到您访问代码。
我Attemps:
#!/bin/sh
for file in "[email protected]" do
if file "$file" | grep "ASCII text, with CRLF"; then
echo "converting $file"
sed -e s/[\\r\\n]//g "$file"
fi
done
结果:
./asciiFix.sh: 3: ./asciiFix.sh: Syntax error: "if" unexpected (expecting "do")
aardvark.cpp /home/cs252/Assignments/scriptAsst/winscrubbed.dat differ: byte 50, line 1
Failed: incorrect file conversion when running ./asciiFix.sh 'aardvark.cpp' 'bongo.dat' ' cat.dog.bak
㈡曾试图取出,如果再。我已经尝试过sed -i's/^ M // g'“$ file”,还使用了dos2unix,以及其他一些我不记得的东西。但它总是说这些文件的转换不正确。
加入后;并切换到DOS2UNIX的:
#!/bin/sh
for file in "[email protected]";
do
if file "$file" | grep "ASCII text, with CRLF"; then
echo "converting $file"
dos2unix "$file"
fi
done
的错误,我现在得到:
dos2unix: converting file aardvark.cpp to Unix format ...
Failed when running: ./asciiFix.sh 'aardvark.cpp' 'bongo.dat' 'cat.dog.bak'
4pm。哪个时区,哈哈? (你还活在光盘上吗?) – 2014-12-13 13:32:32
该作业包含一个不精确的术语“Windows ASCII”。 ASCII是一个定义良好的字符集,但不是(通常)Windows上正在使用的字符集。这里的意图可能是[代码页1252](http://en.wikipedia.org/wiki/Windows-1252),它是西方Windows安装中的默认字符集,但它绝不是唯一可能的解释。当然,他们似乎只关心文件中的行结尾,而不关心它使用的ASCII超集。 – tripleee 2014-12-13 13:43:10
东部时间下午4点 – purpleminion 2014-12-13 17:44:18