This PowerShell implementation provides dynamic column type detection and data validation while creating clean, aligned console output - making it ideal for consistent data snapshots and type verification.
- Dynamically detects and validates column types from CSV data
- Supports multiple data types: Int, Float, Double, Bool, String, and Null
- Creates formatted console tables with proper alignment
- Validates subsequent rows against the detected schema
- Handles duplicate column names with automatic suffixes
- Limits output width with smart string truncation
- Saves output to both console and file
1,"Welcome to dynamic-csv-headers.ps1 Welcome to csv_console_table.ps1",10.00,asdf321654,1,true,3.141592653590
2,"This is a sample data csv file",19.97,321654AE,2,false,2.718281828460
3,"1st row: set header types",1.99,"null",3,true,1.414213562370
4,"This file headers: 'int char* float char* int bool double'",11.99,Can't feel Nothing!,4,true,6.022140760000
5,"Unknown types become `char*/string`",19.97,OU812,5,true,9.806650000000
6,"'gcc -o xyz .\csv_processor.c -lm'",19.17,"string",6,true,1.602176634000
7,"'.\csv_console_table.ps1'",19.84,"char*",7 ,false,6.674300000000
8,"'python -m grip README.md'",16.89,"char*",8,false,2.997924580000
9,"'.\csv_console_table.ps1' yourfile.csv ",19.97,"char*",9,false,1.618033988750-
PowerShell:
- .\csv_console_table.ps1 .\yourfile.csv (optional)
-
BASH:
- pwsh csv_console_table.ps1 yourfile.csv (optional)
- DefaultFile: Path to CSV file (default: "default.csv")
- rowLimit: Maximum rows to process (range: 1-1000, default: 10)
- The script automatically detects these column types:
- Int (whole numbers)
- Float (decimals with at most 2 digits after the decimal point)
- Double (more than 2 digits after the decimal point, an exponent such as
1.5e-3, or a trailingd/Dsuffix such as1.25d). Printed with 6 decimal places (3.141593). Exponent literals print in scientific notation (1.500000e-03) - Bool (true/false)
- String (text)
- Null (empty or null values)
- The script assumes the first row contains column headers.
- Duplicate column names are not supported.
- The output width is limited to 120 characters.
- PowerShell 7.0+
- Read access to CSV files
- This PowerShell implementation offers:
- Dynamic type detection and validation
- Clean console output formatting
- Data integrity verification
- Platform independence
- Educational resource for PowerShell scripting practices
-
PowerShell:
- Import-Csv "data.csv" | Format-Table
-
BASH:
- csvlook -H ./data/generic.csv
- This project is licensed under the MIT License. See the LICENSE file for details.
