awk

涉及内容:

  1. awk
  2. if
  3. for
  4. split
  5. print
  6. for嵌套

  echo 's3://clearml-train-log/video4%2Fhuman_reid/distributed_qa2.7e24d4e98f764883a8e42cb3f362a19d/models' | awk '{len=split($0,a,"/"); for(i=1;i<=len;i++) print a[i]}'
  # 从当前字符串以"/"进行分割,放入数组a中,按长度打印数组a
  # output
  s3:

  clearml-train-log
  video4%2Fhuman_reid
  distributed_qa2.7e24d4e98f764883a8e42cb3f362a19d
  models
  echo 's3://clearml-train-log/video4%2Fhuman_reid/distributed_qa2.7e24d4e98f764883a8e42cb3f362a19d/models' | awk '{len=split($0,a,"/"); for(i=1;i<=len;i++) {len2=split(a[i],b,"."); for(j=1;j<=len2;j++) print b[j]}}'
  # 当前字符串以"/"分割放入数组a,对数组a中每一个元素以"."分割放入数组b,打印b的元素
  # output
  s3:
  clearml-train-log
  video4%2Fhuman_reid
  distributed_qa2
  7e24d4e98f764883a8e42cb3f362a19d
  models
  echo 's3://clearml-train-log/video4%2Fhuman_reid/distributed_qa2.7e24d4e98f764883a8e42cb3f362a19d/models' | awk '{len=split($0,a,"/"); for(i=1;i<=len;i++) {len2=split(a[i],b,"."); if (len2>1) for(j=1;j<=len2;j++) print b[j]}}'
  # 在上面一个example的基础上,如果以"."分割的数组b的长度大于1(至少两个元素),打印数组b
  # output:
  distributed_qa2
  7e24d4e98f764883a8e42cb3f362a19d


posted @ 2022-02-17 20:38  ijpq  阅读(21)  评论(0编辑  收藏  举报