![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | replace Hej Powershell team. In gui-help replace can be defined as - a specified number of times. But how should i do, if i only will change the first space and not the other space in the following example ??? ${C:\powerstart.txt} -replace ' ',';' > C:\powerstart1.txt I need a real reference manual !! -------------------------------------------------------------------- Replace Definition: Returns a string in which a specified substring has been replaced with another substring a specified number of times. $a = "bxnxnx" $a = $a -replace("x","a") Regards Torben Brønsholm Denmark |
My System Specs![]() |
| | #2 (permalink) |
| | Re: replace stratos wrote: Quote: > Hej Powershell team. > > In gui-help replace can be defined as - a specified number of times. > But how should i do, if i only will change the first space and not the other > space > in the following example ??? > > ${C:\powerstart.txt} -replace ' ',';' > C:\powerstart1.txt > > I need a real reference manual !! > -------------------------------------------------------------------- > > Replace > > Definition: Returns a string in which a specified substring has been replaced > with another substring a specified number of times. > > $a = "bxnxnx" > $a = $a -replace("x","a") > > Regards > Torben Brønsholm > Denmark > Sorry, it is going to be the same answer(s)... ;-) Marco -- Microsoft MVP - Windows PowerShell http://www.microsoft.com/mvp PowerGadgets MVP http://www.powergadgets.com/mvp Blog: http://marcoshaw.blogspot.com |
My System Specs![]() |
| | #3 (permalink) |
| | Re: replace # to replace the first space in each line of the file $pattern = '(.*?)( )(.*)' (get-content C:\powerstart.txt) -replace $pattern,'$1;$3' > C:\powerstart1.txt # to replace the first space in the file # pipe its content to out-string and # set the single line option in the regex $pattern = '(?s)(.*?)( )(.*)' (get-content C:\powerstart.txt | out-string) -replace $pattern,'$1;$3' > C:\powerstart1.txt -- Kiron |
My System Specs![]() |
| | #4 (permalink) |
| | RE: replace Thanks for the help i got. My final code was: $pattern = '(?s)(.*?)( )(.*)' ${C:\powerstart.txt} -replace $pattern,'$1;$3' > C:\powerstart1.txt And it works fine |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Replace | PowerShell | |||
| Remove oem and replace with another oem | Vista General | |||
| Replace IE7 with IE6? | Vista General | |||
| Replace sed? | PowerShell | |||
| Using .replace | PowerShell | |||