Skip to content

Latest commit

 

History

History
51 lines (35 loc) · 1.82 KB

README.md

File metadata and controls

51 lines (35 loc) · 1.82 KB

ConvertFrom-FixedWidth

ConvertFrom-FixedWidth is a Powershell function served from the PowerShell Gallery that allows you to take fixed width tabular data and convert it to a PowerShell object array.

Publish to Powershell Gallery

For example, a table of data in a file called "sample1.txt" that has these contents:

Column1   Column2       Column3
038727664 0521829914551 6034
038764    052182991451  60

Can be converted to an object array like this:

# load the file from disk
$fixedWidthText = Get-Content -Path ./sample1.txt

# define the ordinal locations of the columns  (should be one less than the total number of columns)
# in this example the first and second columns are delimited at position 10
# the second column (between Column2 and Column3) is at position 24.  this is 24 positions from the left, not 24 from the prior column
$columns = 10, 24

# use ConvertFrom-FixedWidth function from the PowerShell Gallery to get an object array
$objectTable = ConvertFrom-FixedWidth -FixedWidthTableText $fixedWidthText -ColumnIndexArray $columns

# export the object array as Json just to show what it looks like for debugging
$objectTable | ConvertTo-Json

Installation

If you have the PowerShellGet module installed you can enter the following command:

Install-Module ConvertFrom-FixedWidth

Alternatively you can download a ZIP file of the latest version from our Releases page.

Maintainers

License

This project is licensed under the MIT License.