I have a huge text file (around 500 MB) that is tab delimited. It doesn't contain headers. So it looks like:
20140711 IBM 29.9068 [email protected] this is interesting
20140712 HP 2.3000 [email protected] this is interesting
20140713 GOOGLE 44.9033 [email protected] this is interesting
20140714 HTC 739.70 [email protected] this is interesting
20140715 SAMSUNG 8.442 [email protected] this is interesting
20140716 MICROSOFT 67.104 [email protected] this is interesting
20140717 DELL 5.0823 [email protected] this is interesting
...
...
...
I need to use Powershell to load the text into the SQL Server database as a table. As there is no headers in the text file, the "Import-Csv" cmdlet output the content incorrectly. I think it always treats the first line as headers.
How can "Import-Csv" output whatever in the text file and forget about header config?
Thanks.
By default, the functions read the header of the files. In case you want to read the CSV without header you will need to set to FALSE the header argument.
Go to the File menu, choose 'Open CSV\Tab-Delimited File' (or simply press Ctrl+O), and then from the open dialog-box, choose the tab-delimited file to open. You can copy the tab-delimited string to the clipboard and then use the 'Open Text In Clipboard' option (Ctrl+F7).
You can try this :
$data = Import-Csv C:\temp\F.csv -Header "date","company","value","mail","description" -Delimiter "`t"
$header3 = @("Column_1","Column_2","Column_3","Column_4","Column_5")
$data = Import-Csv $filePath -Header $header3 -Delimiter "`t"
If it's a huge file, may I suggest to use "-Raw' option.
Something like:
$header= "Date EventLog EntryType"
(get-content -Raw $File) | foreach-object {$_ -replace "^", "$header`n"} | set-content $File
Kind regards
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With