然后AWK如果循环条件列值

时间:2015-08-24 18:38:18

标签: if-statement awk

我有3列,我想创建第4列,仅当第3列等于1时才等于第2列(否则,该值可以为0)。

例如,
4 3 1
会成为 4 3 1 3

4 3 2
会成为 4 3 2 0

我尝试了3种方法,在所有情况下,第4列都是零:

'BEGIN {FS = "\t"}; {if ($3!=1) last=0; else last=$2} {print $1, $2, $3, last}'

'BEGIN {FS = "\t"}; {if ($3!=1) print $1, $2, $3, 0; else print $1, $2, $3, $2}'

'BEGIN {FS = "\t"}; {if ($3==1) print $1, $2, $3, $2; else print $1, $2, $3, 0}' 

1 个答案:

答案 0 :(得分:2)

aws cloudwatch get-metric-statistics --namespace AWS/S3 --start-time 2015-07-15T10:00:00 
--end-time 2015-07-31T01:00:00 --period 86400 --statistics Average --region us-east-1 
--metric-name BucketSizeBytes --dimensions Name=BucketName,Value=myBucketNameGoesHere 
Name=StorageType,Value=StandardStorage


Important: You must specify both StorageType and BucketName in the dimensions argument otherwise you will get no results.