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

猜你喜欢

转载自blog.csdn.net/knight_zhou/article/details/106835022