Use this when processing CSV rows one by one and reporting bad rows by line number.
Rows
CSV rows are records, one per line after the header. Validate each row in automation and report bad ones by line number instead of failing the whole import silently.
1. Rows are records; each should have the same number of fields.
2. Watch embedded newlines in quoted fields.
3. Skip/handle blank rows.
4. Count rows for validation.
5. Header row first.
row → fields → record
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Common mistakes Narrow the fault
- Rows with a different number of fields.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- Each row is one record.
- Validate every row before acting.
- Report invalid rows by line number.
wc -l file.csv— row countawk -F, '{print NF}' file.csv | sort | uniq -c— fields per row (simple files)- Header row present — structure
ReferenceWhy it matters1 section · depth on demand
What it is
Each CSV row is one record; the first row usually holds column names.
ReferenceImportant terms & boundaries2 sections · depth on demand
In depth
Rows are the records in a CSV file — one line per item, with fields separated by a delimiter. A header row usually names the columns, which lets scripts read each row as a dictionary instead of relying on column positions.
hostname,ip,site,role
sw-oslo-07,10.20.0.7,oslo,access
sw-oslo-08,10.20.0.8,oslo,access
import csv
with open("devices.csv", newline="", encoding="utf-8") as f:
for row in csv.DictReader(f):
print(row["hostname"], row["ip"])
Validate rows before acting on them: required columns present, no duplicates, valid IP addresses. Spreadsheet exports often add empty rows, trailing spaces and a byte-order mark (use encoding="utf-8-sig").
Mechanics
The linked authority for bounded mechanics is RFC 4180 — Common Format and MIME Type for CSV Files; documentation support is separate from observed lab/production Evidence.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in CSV > Rows. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://www.rfc-editor.org/rfc/rfc4180 · confidence 94%