Export system activity data as CSV with sadf
How sadf turns sar binary data into semicolon-delimited or tab-separated text, what changes in the conversion, and the pitfalls to check before importing it.
sadf is the sysstat utility that reads the binary daily files written by the sar data collector and prints their contents in other formats. If you search for sadf CSV export, the usual answer is the -d option. That answer needs one qualification: the output is delimited text built for databases and scripts, and it is not strictly comma-separated. This review covers what the conversion changes, where it fits, and what to check before you hand the file to a spreadsheet, database or colleague.
Is sadf output suitable for your intended use?
Recommendation: use sadf -d when you need sar history in a form that a database, a script or a spreadsheet can import with a configurable delimiter. Its main benefit is that every record carries the hostname, the sampling interval and a timestamp. Rows from different machines and days can therefore be combined without losing context. The tradeoff is that the format is not plain CSV. Fields are separated by semicolons, header lines begin with a hash sign, and a request for several activities can produce several header blocks with different column sets in one stream. Expect a small cleanup step before strict CSV consumers accept the file.
Ordinary sar text output, or sadf without a format option, is the better choice when a person will read the numbers in a terminal or a report, and you will not import them. sar's columnar output is easier to scan by eye. Delimited output exists for machines, not for skimming.
What the conversion actually changes
In this case, "transformation" means re-serialization. sadf decodes the binary activity file and writes the same recorded statistics as text in the layout you choose. It does not resample or average the data, and it does not alter the stored file. Characters are not reversed, mirrored or substituted, and no visual styling is involved. The output is ordinary ASCII-range text. The changes that matter are structural: how fields are separated, how time is represented, and whether values appear one per row or many per row.
The general command shape puts sadf's own options and the data file first. A double dash follows, and after it come the sar options that select which activities to export. Daily files are commonly stored under /var/log/sa on Red Hat-style systems and under /var/log/sysstat on Debian-style systems, named by day of month. Check your distribution's packaging before relying on either path.
# CPU utilization from the file for the 15th, database-friendly format
sadf -d /var/log/sa/sa15 -- -u
# Memory and CPU, all activities on one line per sample
sadf -d -h /var/log/sa/sa15 -- -u -r
# Restrict to a time window
sadf -d -s 09:00:00 -e 17:00:00 /var/log/sa/sa15 -- -u
With -d, a header line beginning with "# " names the columns. It is followed by one record per sample, and per device or CPU where applicable. For CPU utilization the header has this general shape. The exact column list depends on your sysstat version and the options you pass, so read the header from your own output rather than assuming it.
# hostname;interval;timestamp;CPU;%user;%nice;%system;%iowait;%steal;%idle
Each output format reshapes the same data differently:
| Option | Shape of output | Suited to |
| -d | Semicolon-separated, one record per sample, header lines prefixed with "# " | Database loading, spreadsheets with a configurable delimiter |
| -d -h | Semicolon-separated, all requested activities on a single line per sample | Wide tables where one row per timestamp is wanted |
| -p | Tab-separated, one value per line with hostname, interval, timestamp, device, field name and value | awk, grep and other line-oriented processing; long-format (tidy) data |
| -j | JSON | Programs that need explicit structure rather than positional columns |
| -x | XML | Toolchains that already consume XML |
For a TSV-oriented workflow, note that -p is not a wide TSV table. It writes one measurement per line, which suits pivoting or filtering by field name but produces many more lines than -d does.
Timestamps
Time representation is the most consequential change. In -d and -p output, timestamps default to UTC. The -t option shows the original local time of the machine that created the file. -T shows local time instead of UTC. -U prints seconds since the epoch. Choose one convention before merging files from different hosts or time zones. Mixing conventions silently misaligns rows without causing an import error. Epoch seconds are the least ambiguous choice for databases. UTC strings are easier for people to read.
Will the result remain usable after copying or sharing?
Because the output is plain text, copying and pasting does not change the characters themselves. The risks come from how the receiving tool interprets the delimiters and numbers. Check the following before sharing:
- Delimiter: a tool that assumes commas will place a whole -d record in one column. Either set the import delimiter to semicolon or convert the separators.
- Header prefix: the leading "# " can end up in the first column name, or the tool may treat the line as a comment and skip it. Strip it if you want a clean header row.
- Multiple header blocks: requesting several activities without -h yields separate sections with different columns. Most CSV readers expect a single header. Export one activity per file, or use -h, when the destination needs one rectangular table.
- Decimal separator: sysstat number formatting can follow the locale. A comma decimal mark would conflict with a comma delimiter. Setting LC_ALL=C for the sadf command is a common precaution. Confirm the result on your own system rather than assuming the default.
- Non-data records: data files can contain markers such as system restarts or comments. These may appear as rows that do not match the column header. Inspect the output and filter such rows if your importer rejects irregular lines.
When the destination requires strict comma-separated values, a short pipeline handles the conversion. It is reasonable here because hostnames, device names and numeric fields do not normally contain commas. Verify this for your data, especially device or interface names, before relying on it.
LC_ALL=C sadf -d /var/log/sa/sa15 -- -u \
| sed -e 's/^# //' -e 's/;/,/g' > cpu-15.csv
Accessibility follows from the destination rather than from sadf. A raw delimited file read aloud by a screen reader is a stream of separators and numbers, which is hard to follow. A spreadsheet or database view presents the same data as navigable cells. If people rather than programs will consume the export, share it through a tool that exposes rows and column headers, or provide a short plain-text summary of the figures that matter. Search and editing are unaffected because nothing in the output is stylized or substituted.
Gaps in this review
No subject-specific evidence was supplied for this article. The behavior described above reflects sadf's documented options, and the sysstat manual page for your installed version is the authority. It has not been checked against a particular sysstat release, distribution or spreadsheet product. Exact column lists, the timestamp string format, the handling of restart records and locale effects on numbers can vary between versions. No import into any named spreadsheet, database or assistive technology was tested here. Run a small export and open it in your actual destination before building a workflow around it.