awk
涉及内容:
- awk
- if
- for
- split
- 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
本文来自博客园,作者:ijpq,转载请注明原文链接:https://www.cnblogs.com/ijpq/p/15906322.html