awk中split函數的用法

官方解釋: 

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

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章