I am using SELECT-STRING to filter a large tab-delimited text file so I can work with the file in subsets. However, I find that the resulting output file has had all of the tabs expanded to spaces. I have been able to reproduce the issue
on two different systems running PowerShell v2 under both Windows 7 and Windows 8. I would like to change this behavior to NOT expand the tabs. I need to maintain the tab-delimited format because one field in each row can contain a large block
of arbitrary text, and 'tab' is one of a very few characters (if not the only) that cannot appear in that field.
How can I prevent tab expansion in SELECT STRING?
Steps to reproduce the issue:
Here is a very simple test case. Save the following text in a file called test_data.txt:
ID NAME STATE
001 Joe Arizona
002 Bill Florida
003 Jenny Colorado
005 Anna Arizona
Use the following command line to extract a couple of lines:
Select-String -Pattern "Arizona" -Path .\test_data.txt -SimpleMatch | Out-File -FilePath .\test_output.txt
Open test_output.txt in notepad (or another text editor):
test_data.txt:1:001 Joe Arizona
test_data.txt:4:005 Anna Arizona
Note that the tabs have been expanded into spaces.
Note also that the following command line returns no results:
Select-String -Pattern "Arizona" -Path .\test_data.txt -SimpleMatch | Select-String -Pattern "`t" -SimpleMatch
This ensures that the behavior is coming from Select-String, not from Out-File.
I have also tested the following command line:
Get-Content .\test_data.txt | ? { $_ -like "*Arizona*" } | Out-File .\test_out.txt
This does not exhibit the same issue, but it appears to run more slowly than using Select-String.
Thanks in advance for any and all assistance!
Jamie