編輯:固定。現在關注優化代碼。獲取錯誤:sed:-e表達式#1,字符2:未知命令:`。'
我正在寫一個腳本來將數據從一個文件分離到多個文件中。當我運行腳本時,出現錯誤:「sed:-e表達式#1,字符2:未知命令:`。'」,沒有任何行號,這使得調試有點困難。我已經檢查了單獨使用sed的行,並且它們沒有問題。有任何想法嗎?我意識到,我做了很多事情,我做了一些非常規的事情,有更快的方式做某些事情(我確定有一種方法可以避免不斷導入某些文件),但現在我只是想了解這一點錯誤。下面是代碼:
x1=$(sed -n '1p' < somefile | cut -f1)
y1=$(sed -n '1p' < somefile | cut -f2)
p='p'
for i in 1..$(seq 1 $(cat "somefile" | wc -l))
do
x2=$(sed -n $i$p < somefile | cut -f1)
y2=$(sed -n $i$p < somefile | cut -f1)
if [ "$x1" = "$x2" ] && [ "$y1" = "$y2" ];
then
x1=$x2
y1=$x2
fi
s="$(sed -n $i$p < somefile | cut -f3) $(sed -n $i$p < somefile | cut$
echo $s >> "$x1-$y1.txt"
done
感謝。非常感激。您的更正也會顯着加快速度。 – user2452830
現在它給了我:script2.sh:1:script2.sh:語法錯誤:重定向意外。知道這是爲什麼? – user2452830
另外,我實際上並沒有剪切和粘貼。我只是忘記了我在看哪一個。謝謝你指出,雖然。我也沒有明白。 – user2452830