这是我的问题:
我有一个数字列表:总共183行(在csv文件或txt文件中)
437735121495357
323099286491547
453369992736587
556548989085878
我需要取一行15位数并替换变量:%VariableUID在这个文件中,不断地对所有数字行和变量进行替换
dn: uid=%VariableUID, ou=People, o=aims.edu, o=cp
changetype: modify
delete: pdsRole
pdsRole: generic
-
add: pdsRole
pdsRole: student
dn: uid=%VariableUID, ou=People, o=aims.edu, o=cp
changetype: modify
delete: pdsRole
pdsRole: generic
-
add: pdsRole
pdsRole: student
dn: uid=%VariableUID, ou=People, o=aims.edu, o=cp
changetype: modify
delete: pdsRole
pdsRole: generic
每个%VariableUID将被下一组数字替换
答案 0 :(得分:0)
因此,经过越来越多的搜索,我最终用PowerShell脚本回答了我自己的问题。我无法修改现有模板。但是我能够使用powershell脚本格式化txt文件来替换我的模板:
#Location of Source File and Alias
$Source= gc "C:\Users\amoore19\Desktop\LDAP\ui-3rd-party.txt"
#takes each row in the Source File and replace the variable: $ouid in the following format
foreach ($ouid in $Source)
{
write-output "
dn: uid=$ouid, ou=People, o=aims.edu, o=cp
changetype: modify
delete: pdsRole
pdsRole: generic
-
add: pdsRole
pdsRole: student" | Out-File -filepath "C:\Users\amoore19\Desktop\LDAP\ui-3rd-party-test1.txt" -append
#sets the output location filename and appends each invidiual output at the bottom of existing output (instead of replacing)
}
结果如下:
dn: uid=437735121495324, ou=People, o=aims.edu, o=cp
changetype: modify
delete: pdsRole
pdsRole: generic
-
add: pdsRole
pdsRole: student
dn: uid=323099286491410, ou=People, o=aims.edu, o=cp
changetype: modify
delete: pdsRole
pdsRole: generic
-
add: pdsRole
pdsRole: student