I need to remove ONLY the TABs from within double quotes from a TAB delimited file. I do not know how to detect double quotes that are actual fields vs double quotes in the string itself. I don't want to accidentally remove actual TAB field delimiters (of course).
I have a skeleton script where I believe I need to do some work with the $_ object/record but I don't know what the next step is to detect all fields to then scrub them of any TABs without removing actual Delimiters. I placed a comment in the CODE snippet stating where I believe the processing of the data fields should occur.
Raw data
_record_number record_id id_testing Notes IntakeComplete
111 6 5 " We will not be testing because of covid 19" 1
222 6 5 " We will not be "testing because of covid 19" 1
333 6 5 " We will not be "testing" because of covid 19" 1
The easiest case to solve for is the _record_number 111. I had one record with one single double quote inside two double quotes within tabs. Really odd, and so I replicated that issue in _record_number 222.
The Code
#-Import TABs Inside Quotes Issue.tsv
#-Declare File Paths
$SourceFile = "TABs Inside Quotes Issue.tsv"
$ExportFile = "TABs Inside Quotes Issue_Updated.tsv"
#---------- Attempt to find Double Quoted Fields and Remove TABs ONLY within them and therefore leaving the TAB delimiters untouched
Import-Csv $SourceFile -Delimiter "`t" |
ForEach-Object {
#-Process Data Fields Here
$_
} |
Export-Csv $ExportFile -Delimiter "`t" -UseQuotes Never -NoTypeInformation
TL;DR
The issue I'm having with using the above code to fix my data issues is that I am fixing each issue for each field as they come up. How do I apply a standard fix to ALL fields? Meaning, how do write the script to check the entire Row of columns as opposed to coding in each column and then checking the data?
If you're curious why am I using -UseQuotes Never in the Export-Csv I am doing that due to the fact that BCP requires all of the quotes to be removed due to the BCP Utility not able to handle quoted fields. Using the -UseQuotes Never parameter/value when exporting a CSV via PowerShell Export-Csv Cmdlet it removes just about every single quote but it does this without first removing any Delimiter characters from within the Quoted fields. It also produces unexpected results at times for Quoted fields containing quotes within. Regardless the issue that is causing me grief are the TABs within Quoted Fields that are themselves delimited via TABs.

-replace '(?<=")\t+'might help but as Olaf noted, its better to have the raw data for testing"abc"{tab}"def{tab}ghi"{tab}"kjl\"mno"The second column contains a tab, the third column contains a quote