0
我需要修剪在UNIX shell腳本下面的路徑,請您建議修剪源文件路徑
- 輸入 -
/vobs/java/server/forms/data/Branch/semanticexplorer.pls
- 輸出 -
server/forms/data/Branch/semanticexplorer.pls
我需要修剪在UNIX shell腳本下面的路徑,請您建議修剪源文件路徑
/vobs/java/server/forms/data/Branch/semanticexplorer.pls
server/forms/data/Branch/semanticexplorer.pls
你」我們沒有給出任何修剪的一般標準 - 所以我砍掉了固定的前兩個組件。
這樣的機制避免了執行過程:
input=/vobs/java/server/forms/data/Branch/semanticexplorer.pls
output=${input#/vobs/java/}
Bash有一些擴展,這將是更普遍的路徑微調有用。 Korn外殼支持${var#prefix}
表示法。
您還可以使用:
prefix=/vobs/java/
input=/vobs/java/server/forms/data/Branch/semanticexplorer.pls
output=${input#$prefix}
這可以讓你改變前綴,仍然將其刪除。
在大多數炮彈,蠻力的方法是:
input=/vobs/java/server/forms/data/Branch/semanticexplorer.pls
output=$(echo $input | sed "s%/vobs/java/%%")
在bash:
input=/vobs/java/server/forms/data/Branch/semanticexplorer.pls
output=$(sed "s%/vobs/java/%%" <<< $input)
echo $pathname | sed -E 's/\/([^/]*\/){2}//'
是目錄層次結構/的VOB/java的總是相同的或者它有什麼不同? – roundrobin 2011-01-05 13:20:56