![](/img/trans.png)
[英]How can I check the first character in a string in Bash or Unix shell?
[英]How do I remove a character from a string in a Unix shell script?
我有幾個文件名如下:file - name.txt
如何在UNIX中使用bash腳本從所有文件中刪除“ - ”?
如果我理解正確,請嘗試rename ' - ' '' *
堅持下去!
# Iterate each file in the current directory.
for i in *; do
# Move the file to the new filename, replacing ' - ' with '_'
mv "$i" `echo $i | sed 's/ - /_/g'`
done
使用參數擴展刪除要刪除的字符串部分。 確保使用雙引號來防止mv
誤解輸入。
for i in ./*' - '*; do
mv "$i" "${i// - }"
done
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.