官方解釋:
The awk function split(s,a,sep) splits a string s into an awk array a using the delimiter sep.
awk的功能拆分(s,a,sep)分割字符串s轉換爲使用的分隔符sep的一個a的awk數組
實例
cat datefile
12:34:56
使用awk進行過濾
cat datefile | awk '{split($0,a,":" ); print a[1]}' # 輸出 12
cat datefile | awk '{split($0,a,":" ); print a[3]}' # 輸出56
cat datefile | awk '{split($0,a,":" ); print a[1], a[2], a[3]}' #輸出 12:34:56
遍歷出來:
cat datefile | awk '{split($0,a,":" ); print a[1], a[2], a[3]}'
輸出結果如下:
12
34
56