A CSV header is an optional first line whose fields provide titles for the file’s columns. For example, a cities file can begin with titles such as City and State, followed by data records. section 7.1
Use a header when column names should travel with the data:
- Treat the first line as a header only when the input format indicates that it has one. section 7.1
- Keep the header’s fields aligned with the fields in each record. section 7.1
- Account for delimiters other than commas and for quoted fields when reading real-world CSV files. section 7.1
Viewing a CSV header
The first four lines of cities.csv show a header followed by records. Running csview with --with-header lets the tool use those titles when displaying selected columns, producing City and State headings for matching rows. section 7.1
shell $ head -n 4 cities.csv "LatD","LatM","LatS","NS","LonD","LonM","LonS","EW","City","State" 41, 5, 59, "N", 80, 39, 0, "W", "Youngstown", OH 42, 52, 48, "N", 97, 23, 23, "W", "Yankton", SD 46, 35, 59, "N", 120, 30, 36, "W", "Yakima", WA shell $ csview --in=cities.csv --with-header --search=Ya --slice="8,10" ------------------- | City | State | +---------+-------+ | Yankton | SD | | Yakima | WA | -------------------
Inspect the complete cities.csv sample and its header-aware csview output. section 7.1
Header can also name a format-specific metadata prefix. In PNM images, the header contains a magic number and dimensions; comments may appear there, and the header is always ASCII. section 12.1.1


