Search code examples
powershelltexttrim

Remove Quotes from Textfile without trimming first and last quote of the line


I use jpl files to assign Data in my DataLake. In these text files I experience 3rd Quotes in between the original ones that mess up my allocation system.

Bsp:
dok_dat_feld_61[1]="Order **"**3000000005".

I tried a few things like:

$Variable.Replace("`"","")

$v.Trim('"')

I Expected to clean out all Quotes and Replace the originals at the beginning of the Strings but this system was very very slow especially if you have thousands of files.

I also Tried Indexing the Quotes per Line but failed due to me not knowing how to code.


Solution

  • You can try splitting in 3 parts the string and concat it again. I try this and it works:

    # Original string
    $stringa = 'odok_dat_feld_61[1]="Order **"**3000000005"'
    
    # Split the string at the second "
    $parts = $stringa -split '"', 3
    
    # Reconstruct the string without the second "
    $stringa = $parts[0] + '"' + $parts[1] + $parts[2]
    
    # Output the transformed string
    Write-Output $stringa
    

    This is my result

    Write-Output $stringa
    odok_dat_feld_61[1]="Order ****3000000005"
    
    Write-Output $parts
    odok_dat_feld_61[1]=
    Order **
    **3000000005"