Skeletor 92 Posted Wednesday at 09:14 AM Share Posted Wednesday at 09:14 AM Hi All, I've been staring at this for long and have no idea how to resolve this. I have a csv that Powershell created. It produces double quotes around the file. Im want to remove the double quotes using StringRegExpReplace. $PShell_Path = "GetIPAddress.PS1" FileWrite("GetIPAddress.PS1", "Get-NetIPAddress -AddressFamily IPv4 | Select-Object InterfaceAlias, IPAddress | Export-Csv -Path 'results.csv' -NoTypeInformation") $command = "powershell.exe -ExecutionPolicy Bypass -File " & $PShell_Path Run(@ComSpec & " /c " & $command, "", @SW_HIDE) ; Read the contents of the CSV file into a string Global $sContents = FileRead("results.csv") ; Replace all double quotes with a single quote using StringRegExpReplace() $sContents = StringRegExpReplace($sContents, '"', "'", "G") ; Write the modified contents back to the CSV file FileWrite("results.csv", $sContents) I dont see the result, $sContents provides a blank file or doesnt even write to the file. Kind RegardsSkeletor "I need coffee to turn me back to a human" Microsoft Office Splash Screen | Basic Notepad Program (Beginner) | Transparent Splash Screen Link to post Share on other sites
ajag 15 Posted Wednesday at 09:50 AM Share Posted Wednesday at 09:50 AM Your syntax seems to be not correct. 4th parameter is "G", but it should be a "count" parameter: StringRegExpReplace ( "test", "pattern", "replace" [, count = 0] ) Maybe some error handling hepls (check @error). Rule #1: Always do a backup Rule #2: Always do a backup (backup of rule #1) Link to post Share on other sites
Solution Skeletor 92 Posted Wednesday at 10:22 AM Author Solution Share Posted Wednesday at 10:22 AM (edited) Thanks @ajag, removed it, but the actual issue was infact a delay in file creation. I used RunWait and used brackets in my regex for the quotes and this resolved my issue. $PShell_Path = "GetIPAddress.PS1" FileWrite("GetIPAddress.PS1", "Get-NetIPAddress -AddressFamily IPv4 | Select-Object InterfaceAlias, IPAddress | Export-Csv -Path 'results.csv' -NoTypeInformation") $command = "powershell.exe -ExecutionPolicy Bypass -File " & $PShell_Path RunWait(@ComSpec & " /c " & $command, "", @SW_HIDE) ; Read the contents of the CSV file into a string Global $sContents = FileRead("results.csv") ; Replace all double quotes with a single quote using StringRegExpReplace() $sContents = StringRegExpReplace($sContents, '["]', "") ; Write the modified contents back to the CSV file FileOpen("results.csv", 2) FileWrite("results.csv", $sContents) FileClose("results.csv") Edited Wednesday at 10:24 AM by Skeletor Kind RegardsSkeletor "I need coffee to turn me back to a human" Microsoft Office Splash Screen | Basic Notepad Program (Beginner) | Transparent Splash Screen Link to post Share on other sites
pixelsearch 514 Posted Wednesday at 12:36 PM Share Posted Wednesday at 12:36 PM Hi Skeletor Glad you solved your issue. I got a question : why are the brackets needed ? If I run the following script, then I got the same result, with or without brackets : $sSubject = '"123"' & "|" & '"456"' ConsoleWrite($sSubject & @crlf & @crlf) $sContent1 = StringRegExpReplace($sSubject, '"', "") ConsoleWrite($sContent1 & @crlf) $sContent2 = StringRegExpReplace($sSubject, '["]', "") ConsoleWrite($sContent2 & @crlf) Scite Console : "123"|"456" 123|456 123|456 Link to post Share on other sites
Skeletor 92 Posted Wednesday at 09:14 PM Author Share Posted Wednesday at 09:14 PM Excellent pixelsearch, thanks for picking this up. I was actually browsing the help files to find a solution and throwing everything into it. I seriously do not understand these expressions. Kind RegardsSkeletor "I need coffee to turn me back to a human" Microsoft Office Splash Screen | Basic Notepad Program (Beginner) | Transparent Splash Screen Link to post Share on other sites
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now