문자 앞에 쉼표 추가

문자 앞에 쉼표 추가

다음 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

string 으로 시작하지 않는 줄은 arn:aws:iam아무것도 변경하지 마세요 .

답변1

그리고 sed:

sed 's/^\([^,]*\)\(,"arn:aws:iam:\)/\1,\2/'

답변2

awk해결책:

awk 'BEGIN{ FS=OFS="," }$2 ~ /^"arn:aws:iam:/{ $2 = ","$2 }1' file.csv
  • $2 ~ /^"arn:aws:iam:/- 두 번째 필드가 다음 $2으로 시작 하는 경우"arn:aws:iam:
  • $2 = ","$2- 두 번째 필드 값 앞에 추가,

산출:

"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",

관련 정보