If a combined CSV repeats its column heading between batches, you can make a Finder Quick Action that keeps the first line and removes later lines that match it exactly. The action below writes a separate .cleaned.csv file beside each selected file, leaving the original untouched. It works for ordinary CSV exports where each record occupies one line; it does not parse every valid CSV format.
What the Quick Action will do
The workflow compares complete lines, not individual CSV fields. It saves the first line as the header, copies it to the output, then skips any later line identical to that header. Other rows stay in their original order, including repeated data rows. This is a practical choice when exported batches insert the same heading between records.
The method uses macOS’s built-in awk through Automator’s Run Shell Script action. Apple documents both creating Finder Quick Actions and adding shell scripts to Automator workflows. Create a Quick Action workflow · Use a shell script action in an Automator workflow
Create the Finder Quick Action
- Open Automator, choose File > New, select Quick Action, then click Choose.
- At the top of the workflow, set Workflow receives current to files or folders and set the application to Finder.
- Find Run Shell Script in the Actions library and drag it into the workflow.
- Set Shell to
/bin/zshand Pass input to as arguments. Paste the script below into the action.
for file in "$@"; do
if [ ! -f "$file" ]; then
printf 'Not a regular file: %s\n' "$file" >&2
exit 1
fi
output="${file}.cleaned.csv"
if [ -e "$output" ]; then
printf 'Output already exists; skipped: %s\n' "$output" >&2
exit 1
fi
temporary=$(mktemp "${file}.tmp.XXXXXX") || exit 1
if awk 'NR == 1 { header = $0; print; next }
$0 != header { print }' "$file" > "$temporary"; then
if ! mv "$temporary" "$output"; then
rm -f "$temporary"
exit 1
fi
else
rm -f "$temporary"
exit 1
fi
done
Save the workflow with a name such as Remove Repeated CSV Headers. The temporary file is created beside the source, then moved to the output name after processing. If that output already exists, the script stops instead of replacing it. The original input is never targeted for writing.
Run it and check the result
In Finder, select one or more CSV files, open the contextual Quick Actions menu, and choose Remove Repeated CSV Headers. Look beside each source for a file ending in .cleaned.csv. Open the result in a text editor or spreadsheet and check that it still has one heading and that rows before and after each repeated heading remain present. The workflow does not show a custom completion message; a file that was not produced may mean the output already existed or a processing error occurred.
The comparison is exact: a heading with different capitalization, spacing, punctuation, or quoting is treated as a different line and will remain. That constraint is intentional here; it avoids guessing which rows count as headings when the file’s text varies.
Know when this line-based method is unsuitable
CSV can contain quoted fields with embedded newline characters. In that case, a logical CSV record may span several physical lines, while awk processes input as lines. This script could then mistake a line inside a field for a record or disrupt the file. Apple’s macOS awk manual describes its line-oriented processing; for multiline CSV, use a CSV-aware tool that supports the file’s format instead. macOS awk manual
This Quick Action also does not normalize whitespace, remove near-matches, inspect column names, or merge files. It is suited to a narrow cleanup: removing exact repetitions of the first physical line from line-based CSV exports while preserving the source for review.
Sources
- Create a Quick Action workflow in Automator on Mac — Apple Support
- Use a shell script action in an Automator workflow on Mac — Apple Support
- awk(1) — macOS 13.6.5 Manual Pages — FreeBSD Manual Pages