我有这个 CSV 文件:
"ADFS-Administrators","Administrator-Access","arn:aws:iam::279052847476:saml-provider/companyADFS"
"ADFS-amtest-ro","arn:aws:iam::279052847476:saml-provider/companyADFS"
"AWSAccCorpAdmin","arn:aws:iam::279052847476:saml-provider/LastPass"
"AWScompanyCorpAdmin","arn:aws:iam::279052847476:saml-provider/LastPass"
"AWScompanyCorpPowerUser","arn:aws:iam::279052847476:saml-provider/LastPass"
"flowlogsRole","oneClick_flowlogsRole_1495032428381",
"companyDevShutdownEC2Instaces","oneClick_lambda_basic_execution_1516271285849",
"companySAMLUser","arn:aws:iam::279052847476:saml-provider/companyAzureAD"
"lambda_stop_rundeck_instance","oneClick_lambda_basic_execution_1519651160794",
"OneLoginAdmin","arn:aws:iam::279052847476:saml-provider/OneLoginAdmin"
"OneLoginDev","arn:aws:iam::279052847476:saml-provider/OneLoginDev"
"vmimport","vmimport",
"workspaces_DefaultRole","SkyLightServiceAccess",
如果在第一个逗号之后有一个以开头的字符串,我想在每一行中添加另一个逗号arn:aws:iam:
所需输出(部分):
"ADFS-amtest-ro",,"arn:aws:iam::279052847476:saml-provider/companyADFS"
"AWSAccCorpAdmin",,"arn:aws:iam::279052847476:saml-provider/LastPass"
"AWScompanyCorpAdmin",,"arn:aws:iam::279052847476:saml-provider/LastPass"
"AWScompanyCorpPowerUser",,"arn:aws:iam::279052847476:saml-provider/LastPass
对于没有以 开头的字符串的行arn:aws:iam
,不要更改任何内容。
awk
解决方案:$2 ~ /^"arn:aws:iam:/
- 如果第二个字段$2
以"arn:aws:iam:
$2 = ","$2
- 在第二个字段值前面加上,
输出:
与
sed
: