想象一下,我們正在運行簡單的git diff --name-only
。輸出將是這樣的:解析文件列表
/path1/path2/path3/path4/file1
/path1/path2/path3/path4/file2
/path1/path2/file3
/file4
/path1/file5
的目標是有這樣的功能,將能夠分析和計算路徑中的任何部分。例如,如果我運行:
// 1 -> is the column to watch/count.
// In example output above it is: path1, path1, path1, path4, path1
// For 2 -> path2, path2, path2, null, file5
// For 3 -> path3, path3, file3, null, null
git diff --name-only | someFn(1)
它應輸出不同匹配的總數。 例如:
1 -> should output 2 (path1, file4)
2 -> should output 3 (path2, null, file5)
3 -> should output 3 (path3, file3, null)
函數的輸出應該是一個簡單的數字0, 1, 2..
誰能幫我呢? 感謝
哪個版本的bash('echo $ BASH_VERSION')?我問,因爲這是一個顯而易見的關聯數組的使用。那些在bash 4.0中,否則我們可以使用'awk'。 – cdarke
$ BASH_VERSION是3.2.57(1)-release – user2573863
@ hek2mgl我試圖用'grep -e'失敗。和'awk'的不同組合。 – user2573863