我的 bash 腳本沒什么問題。該腳本將存盤庫克隆到我的本地檔案夾,然后在這些存盤庫中搜索具有指定擴展名的檔案(結果為 CSVtemporary2/ASSETS-LIST-"$dir".csv),然后編輯結果(剪切路徑的前 4 個元素,結果為:/CSVtoGD2/"$dir".csv)
在 CSV 中,每行 ex 中都有檔案路徑。/users/krzysztofpaszta/temporaryprojects/gamex/car1.png /users/krzysztofpaszta/temporaryprojects/gamex/sound1.mp3 (...)
腳本的每個部分都作業正常,但在剪切路徑的前 4 個元素后,第一行被洗掉。我不知道為什么會這樣。
所以結果應該是:
/car1.png
/sound1.mp3 (...)
但結果是:
/sound1.mp3 (...)
我不知道為什么會這樣。
換句話說,檔案 CSVtemporary2/ASSETS-LIST-"$dir".csv 很好,但是檔案 /CSVtoGD2/"$dir".csv 已洗掉第一行。有人知道為什么會這樣嗎?
#!/bin/bash
rm -vrf /Users/krzysztofpaszta/CSVtoGD2/*
rm -vrf /Users/krzysztofpaszta/CSVtemporary2/*
cd /Users/krzysztofpaszta/temporaryprojects
for repo in $(cat /users/krzysztofpaszta/repolinks.csv); do
git clone "$repo"
dir=${repo##*/}
find /users/krzysztofpaszta/temporaryprojects/"$dir" -name "*.fnt" -o -name "*.png" -o -name "*.ttf" -o -name "*.asset" -o -name "*.jpeg" -o -name "*.tga" -o -name "*.tif" -o -name "*.bmp" -o -name "*.jpg" -o -name "*.fbx" -o -name "*.prefab" -o -name "*.flare" -o -name "*.ogg" -o -name "*.wav" -o -name "*.anim" -o -name "*.mp3" -o -name "*.tiff" -o -name "*.otf" -o -name "*.hdr" >> /users/krzysztofpaszta/CSVtemporary2/ASSETS-LIST-"$dir".csv
while read in ; do
cut -d'/' -f6- >> /users/krzysztofpaszta/CSVtoGD2/"$dir".csv #| awk 'BEGIN{print"//"}1' - adding first empty row is not the solution, first row with text is still deleted
done < /users/krzysztofpaszta/CSVtemporary2/ASSETS-LIST-"$dir".csv
done
#rm -vrf /Users/krzysztofpaszta/temporaryprojects/*
#echo Repo deleted
uj5u.com熱心網友回復:
你的語法
while read in ; do
cut -d'/' ^f6- >> /users/krzysztofpaszta/CSVtoGD2/"$dir".csv
done < /users/krzysztofpaszta/CSVtemporary2/ASSETS-LIST-"$dir".csv
不會像你期望的那樣作業。
該read命令讀取 csv 檔案的第一行并為其分配一個變數in。然后將剩余的行通過標準輸入提供給cut命令。
相反,你可以說;
while IFS= read -r line; do
cut -d'/' ^f6- <<< "$line" >> /users/krzysztofpaszta/CSVtoGD2/"$dir".csv
done < /users/krzysztofpaszta/CSVtemporary2/ASSETS-LIST-"$dir".csv
實際上你甚至不需要使用while回圈:
cut -d'/' ^f6- < /users/krzysztofpaszta/CSVtemporary2/ASSETS-LIST-"$dir".csv > /users/krzysztofpaszta/CSVtoGD2/"$dir".csv
除此之外還有很多需要改進的地方:
- 路徑名
/Users或/users. - 您可以使用
while .. read ..回圈而不是for repo in $(cat path/to.csv) - 您不需要為
find.cut您可以通過管道將輸出直接提供給命令。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/490631.html
