Home > database >  Using Windows powershell, how can I delete all strings directly in between ";" or ",&
Using Windows powershell, how can I delete all strings directly in between ";" or ",&

Time:09-22

I have

598842,3605false;3605true;36054true;36054true;360true;360false;36054true
598842, 3605true;36054true;36054true;360true;360false;36054true

I want to turn it into

598842, 3605true;36054true;36054true;360true;36054true
598842, 3605true;36054true;36054true;360true;36054true

Pathetic attempts below.

(Get-Content -Raw .\actswithpeople.csv)  -Replace '.*?(\"totalCount\":)', '' | Out-File -FilePath actpageline.txt -Force -Encoding ASCII
    (Get-Content -Raw .\actswithpeople.csv)  -Replace '.*?(\"false;\":)', '' | Out-File -FilePath actpageline.txt -Force -Encoding ASCII
    (Get-Content -Raw .\actswithpeople.csv)  -Replace '\",\".*?(\"false;\":)', '' | Out-File -FilePath actpageline.txt -Force -Encoding ASCII
    (Get-Content -Raw .\actswithpeople.csv)  -Replace '.*?(\"false;\":)', '' | Out-File -FilePath actpageline.txt -Force -Encoding ASCII
    [regex]::Replace((Get-Content -Raw .\actswithpeople.csv), '(?s); \[false]', { param($match) $match.Value -replace '' }) | Out-File -FilePath noo.csv -Force -Encoding ASCII
    [regex]::Replace((Get-Content -Raw .\actswithpeople.csv), '(?s);\[false]', { param($match) $match.Value -replace '' }) | Out-File -FilePath noo.csv -Force -Encoding ASCII
    [regex]::Replace((Get-Content -Raw .\actswithpeople.csv), '(?s);\[false]', { param($match) $match.Value -replace '' }) | Out-File -FilePath noo.csv -Force -Encoding ASCII
    [regex]::Replace((Get-Content -Raw .\actswithpeople.csv), ',(?s)\"[false]\"', { param($match) $match.Value -replace '' }) | Out-File -FilePath noo.csv -Force -Encoding ASCII
    [regex]::Replace((Get-Content -Raw .\actswithpeople.csv), '(?s): \[. ?\r?\n        \]', { param($match) $match.Value -replace '[\r\n\"]' }) | Out-File -FilePath noo.csv -Force -Encoding ASCII
    [regex]::Replace((Get-Content -Raw .\actswithpeople.csv), '(?s)\[. ?\r?\n\]', { param($match) $match.Value -replace '' }) | Out-File -FilePath noo.csv -Force -Encoding ASCII
    [regex]::Replace((Get-Content -Raw .\actswithpeople.csv), '(?s)false;\[. ?\r?\n\]', { param($match) $match.Value -replace '' }) | Out-File -FilePath noo.csv -Force -Encoding ASCII
    [regex]::Replace((Get-Content -Raw .\actswithpeople.csv), '(?s)false;. ?\r?\n\', { param($match) $match.Value -replace '' }) | Out-File -FilePath noo.csv -Force -Encoding ASCII
    [regex]::Replace((Get-Content -Raw .\actswithpeople.csv), '(?s)false;. ?\r?\n', { param($match) $match.Value -replace '' }) | Out-File -FilePath noo.csv -Force -Encoding ASCII
    [regex]::Replace((Get-Content -Raw .\actswithpeople.csv), '(?s)false;. ?', { param($match) $match.Value -replace '' }) | Out-File -FilePath noo.csv -Force -Encoding ASCII
    (Get-Content -Raw .\actswithpeople.csv) -replace '(?s)(?<=;.*?)[\r\n"](?=.*?false;)' | Out-File -FilePath noo.csv -Force -Encoding ASCII
    (Get-Content -Raw .\actswithpeople.csv) -replace '(?)(?<=;.*?)[\r\n"](?=.*?false;)' | Out-File -FilePath noo2.csv -Force -Encoding ASCII
    (Get-Content -Raw .\actswithpeople.csv) -replace '(.s)(?<=;.*?)[\r\n"](?=.*?false;)' | Out-File -FilePath noo.csv -Force -Encoding ASCII
    (Get-Content -Raw .\actswithpeople.csv) -replace '(?,)(?<=;.*?)[\r\n"](?=.*?false;)' | Out-File -FilePath noo.csv -Force -Encoding ASCII
    (Get-Content -Raw .\actswithpeople.csv) -replace '(?.)(?<=;.*?)[\r\n"](?=.*?false;)' | Out-File -FilePath noo.csv -Force -Encoding ASCII
    (Get-Content -Raw .\actswithpeople.csv) -replace '(.)(?<=;.*?)[\r\n"](?=.*?false;)' | Out-File -FilePath noo.csv -Force -Encoding ASCII
    (Get-Content -Raw .\actswithpeople.csv) -replace '(.)(?<=,.*?)[\r\n"](?=.*?false;)' | Out-File -FilePath noo.csv -Force -Encoding ASCII
    (Get-Content -Raw .\actswithpeople.csv) -replace '(.)(?<=,.*?)[\r\n"](?=.*?false;)' | Out-File -FilePath noo.csv -Force -Encoding ASCII;(Get-Content -Raw .\noo.csv) -replace 'true','' | Out-File noo2.csv;
    (Get-Content -Raw .\actswithpeople.csv) -replace '(.)(?<=,.*?)[\r\n"](?=.*?false;)' | Out-File -FilePath noo.csv -Force -Encoding ASCII;(Get-Content -Raw .\noo.csv) -replace 'true','' | Out-File noo2.csv;(Get-Content -Raw .\actswithpeople.csv) -replace 'true','' | Out-File actsnotrue.csv
    (Get-Content -Raw .\actswithpeople.csv) -replace '(.)(?<=;.*?)[\r\n"](?=.*?false;)' | Out-File -FilePath noo.csv -Force -Encoding ASCII
    (Get-Content -Raw .\actswithpeople.csv) -replace '(.)(?<=;.*?)(?=.*?false;)' | Out-File -FilePath noo.csv -Force -Encoding ASCII
    (Get-Content -Raw .\actswithpeople.csv) -replace '(.)(?<=true;.*?)(?=.*?false;)' | Out-File -FilePath noo.csv -Force -Encoding ASCII
    (Get-Content -Raw .\actswithpeople.csv) -replace '(.)(?<=;.*?)(?=.*?false;)' | Out-File -FilePath noo.csv -Force -Encoding ASCII
    (Get-Content -Raw .\actswithpeople.csv) -replace '(. ?)(?<=;.*?)(?=.*?false;)' | Out-File -FilePath noo.csv -Force -Encoding ASCII
    (Get-Content -Raw .\actswithpeople.csv) -replace '(. ?)(?<=,. ?)(?=.*?false;)' | Out-File -FilePath noo.csv -Force -Encoding ASCII
    (Get-Content -Raw .\actswithpeople.csv) -replace '(.*?)(?<=,.*?)(?=.*?false;)' | Out-File -FilePath noo.csv -Force -Encoding ASCII
    (Get-Content -Raw .\actswithpeople.csv) -replace '(?<=,.*?)(?=.*?false;)' | Out-File -FilePath noo.csv -Force -Encoding ASCII
    (Get-Content -Raw .\actswithpeople.csv) -replace '(.*?)(?<=;.*?)(?=.*?false;)' | Out-File -FilePath noo.csv -Force -Encoding ASCII
    (Get-Content -Raw .\actswithpeople.csv) -replace '(.*?)(?<=;.*?)(?=.*?false)' | Out-File -FilePath noo.csv -Force -Encoding ASCII
    (Get-Content -Raw .\actswithpeople.csv) -replace '(.*?)(?<=;.*?)(?=false)' | Out-File -FilePath noo.csv -Force -Encoding ASCII
    (Get-Content -Raw .\actswithpeople.csv) -replace '(.)(?<=;)(?=.*?false;)' | Out-File -FilePath noo.csv -Force -Encoding ASCII
    (Get-Content -Raw .\actswithpeople.csv) -replace '(.?)(?<=;)(?=.*?false;)' | Out-File -FilePath noo.csv -Force -Encoding ASCII
    (Get-Content -Raw .\actswithpeople.csv) -replace '(.*?)(?<=;)(?=.*?false;)' | Out-File -FilePath noo.csv -Force -Encoding ASCII
    (Get-Content -Raw .\actswithpeople.csv) -replace '(?<=;.*?)(?=.*?false;)' | Out-File -FilePath noo.csv -Force -Encoding ASCII
    (Get-Content -Raw .\actswithpeople.csv) -replace '.(?<=;.*?)(?=.*?false;)' | Out-File -FilePath noo.csv -Force -Encoding ASCII
    (Get-Content -Raw .\actswithpeople.csv) -replace '.*?(?<=;.*?)(?=.*?false;)' | Out-File -FilePath noo.csv -Force -Encoding ASCII

I didn't save the output of every one. I thought this was a simple one I could crack, but 3 hours later, I was wrong, it isn't. Please help.

CodePudding user response:

Why not just this:

'
598842,3605false;3605true;36054true;36054true;360true;360false;36054true
598842, 3605true;36054true;36054true;360true;360false;36054true
' -replace '\d false;' -replace ', |,', ', '

# Results
<#
598842, 3605true;36054true;36054true;360true;36054true
598842, 3605true;36054true;36054true;360true;36054true
#>
  • Related