chandru_sol
asked on
Powershell to edit multiple strings in text file
Hi,
I am looking for a powershell script to edit multiple lines in a text file where value of the string is with in quotes "value"
Save changes with value_filename
Is this something that can be done to change multiple strings/lines values in txt file using powershell
Thanks
I am looking for a powershell script to edit multiple lines in a text file where value of the string is with in quotes "value"
Save changes with value_filename
Is this something that can be done to change multiple strings/lines values in txt file using powershell
Thanks
Can you provide an example of what you're trying to do?
ASKER
for example i have a file with below entry
deviceManagement[1]["secur ePort"] = "443"
deviceManagement[2]["ifNam e"] = "bdg2"
radiusAttributes[1]["nasId entifier"] = "100"
to
deviceManagement[1]["secur ePort"] = "80"
deviceManagement[2]["ifNam e"] = "dgp2"
radiusAttributes[1]["nasId entifier"] = "25"
There will be 50 + lines for which changes needs to be done either input or from text file
hope it is clear
deviceManagement[1]["secur
deviceManagement[2]["ifNam
radiusAttributes[1]["nasId
to
deviceManagement[1]["secur
deviceManagement[2]["ifNam
radiusAttributes[1]["nasId
There will be 50 + lines for which changes needs to be done either input or from text file
hope it is clear
create txt file with all changes need to be applies, for example:
securePort 80
nasIdentifier 25
the powershell script will look for all entries ["securePort"] and change value to "80"
same thing goes to nasIdentifier.
is that would be ok?
securePort 80
nasIdentifier 25
the powershell script will look for all entries ["securePort"] and change value to "80"
same thing goes to nasIdentifier.
is that would be ok?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
There is something missing in line 9, $value is never set, and I cannot see how you should do that.
Another, similar way:
Another, similar way:
$map = import-csv C:\Temp\Values.txt -delimiter ' ' -header key, value
get-content c:\temp\source.txt | foreach-object {
$line = $_
foreach ($cur in $map)
{ $line = $line -replace "(.+\[""$($cur.key)""\] =).*", "`$1 $($cur.value)" }
$line
} | out-File C:\Temp\Output.txt
Line 9 should be:
$value = $map[$_]
$value = $map[$_]
ASKER
Thanks Guys!!
File extension is .cfg. is it ok to open .cfg in powershell and save it to .cfg without any changes in foramt
KC
File extension is .cfg. is it ok to open .cfg in powershell and save it to .cfg without any changes in foramt
KC
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks! How to find format of existing file?