請幫忙。我需要在這個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