com sed
:
sed 's/^\([^,]*\)\(,"arn:aws:iam:\)/,/'
Eu tenho este arquivo 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",
Eu quero adicionar outra vírgula em cada linha se após a primeira vírgula houver uma string que comece com arn:aws:iam:
Saída desejada (parcial):
"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
Para linhas que não possuem a string que começa com arn:aws:iam
, não altere nada.
awk
solução:
awk 'BEGIN{ FS=OFS="," }$2 ~ /^"arn:aws:iam:/{ $2 = ","$2 }1' file.csv
$2 ~ /^"arn:aws:iam:/
- se o 2º campo $2
começar com "arn:aws:iam:
$2 = ","$2
- prefixar o valor do 2º campo com ,
A saída:
"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",
Tags text-processing csv