import-csv question

 If my input file is delimited by a vertical Bar(|) and data has 2 sets of double quotes around data values would I need
to do anything special other than specify the deliminator when reading the records?


 Data:
Fileseq|recordnbr|specnbr
""001""|""1""|""cs445""

The first record is the header record.

 Thanks.

July 5th, 2013 7:43pm

 My script is doing this...

Import-CSV $file -delimiter '|' | ForEach-Object{


  Now that the data has 2 sets of Double quotes it's not reading formatting data correctly based upon header column. Is there anyway to parse or ignore the double quotes and just process data between Bar delims.

 I also found some data records that had

"001|""2"|"cs446""
 
 Thanks.

 

Free Windows Admin Tool Kit Click here and download it now
July 5th, 2013 9:25pm

"001|""2"|"cs446""

This one's a problem.  Having only an opening quotation mark, but no closing quote before the pipe symbol is a mess.  If none of your data fields will contain a pipe symbol, I'd recommend just stripping all of the double quotes out of the file's contents before treating it as CSV data, like this:

$content = Get-Content -Path $file
$content = $content -replace '"',''

$content | ConvertFrom-Csv -Delimeter '|' | ForEach-Object {
    # do stuff
}

July 5th, 2013 10:04pm

 How does that logic get implemented into my current script...

 Will that replace work for multiple files found during processing?

 
ForEach($file in $files){
    Write-Log "$writelogdir\files-processed.log" "Found files $file"
             
    Import-CSV  $file -delimiter '|' | ForEach-Object{

 # I have a bunch of Do things

Thanks.

Free Windows Admin Tool Kit Click here and download it now
July 6th, 2013 2:28pm

Yep, it should work as-is. Replace your line that starts with "Import-Csv" with the first 3 lines of code I posted.
July 6th, 2013 2:38pm

 Yep ... it worked great !!!!

 Thanks.

Free Windows Admin Tool Kit Click here and download it now
July 6th, 2013 2:43pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics