Read a fixed-width text report (parts)
An old system writes each record as fixed-width text. Cut each line at the right positions and type the result.
- Level
- advanced
- Time
- ~12 min
- Task
- Build the query
- Access
- Free — no account needed
Loading the practice workspace…
About this exercise
What you'll practise
Split text by character positions and clean the padding that fixed-width formats add.
Ironbridge Engineering (fictional) still prints its parts inventory from a 1990s system as fixed-width text.
Steps
ReportFileis a text file with one record per line and no header. Characters 1–6 are the code, 7–26 the name (padded with spaces), and 27–31 the quantity (right-aligned).- Produce columns
Code,NameandQty, with surrounding spaces removed from every value. - Set
Qtyto a whole number.
Your result must
- Columns: Code, Name, Qty
- No padding spaces in Code or Name
- Qty is a whole number
Input
- ReportFile (file)
- Text file; first line: P0001 Spring Pin Set 180
- Every field is text until you set types
Expected output columns
Code (text), Name (text), Qty (number)
| Code | Name | Qty |
|---|---|---|
| P0001 | Spring Pin Set | 180 |
| P0002 | Flat Bolt | 867 |
| P0003 | Flat Washer | 125 |