# CSV Deduplicate & Merge - Combine Files, Remove Duplicates (`kotaro-project/csv-deduplicate-merge`) Actor

Merge several CSV or TSV files into one, match columns even when names differ in case or spacing, and remove duplicate rows on the columns you choose. Ignore extra spaces and case, keep the first or last copy. Get one clean UTF-8 CSV with a download link. No login, no API key.

- **URL**: https://apify.com/kotaro-project/csv-deduplicate-merge.md
- **Developed by:** [KOTARO project](https://apify.com/kotaro-project) (community)
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $3.00 / 1,000 files mergeds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## CSV Deduplicate & Merge

Combine several CSV or TSV files into one clean CSV and remove duplicate rows. Give the file URLs (or paste CSV text), choose which columns decide a duplicate, and get a download link to the merged file.

No login, no API key. Only the files you name are downloaded; internal addresses are refused.

### What it does

- **Matches columns by name**, even when files spell them differently: `Product Name`, `product_name` and `PRODUCT-NAME` are one column (or choose exact matching).
- **Removes duplicates** on the columns you choose (or on whole rows), ignoring extra spaces and upper/lower case if you want. The values written to the file are never changed.
- **Keeps the first or the last copy**, so later (newer) files can replace older rows.
- **All columns or only common ones**: missing cells stay empty.
- Optional `source` column showing which file each row came from.
- Detects comma, tab, semicolon and pipe, and UTF-8, UTF-16, Shift_JIS and Latin-1. The result is UTF-8.

### Output

One row with `downloadUrl` (merged.csv), rows read and written, duplicates removed, the final columns, and a per-file report (rows added, duplicates dropped, columns not used). Files that could not be read are listed in `notRead`.

### Sample input

Merges the public [country list](https://github.com/datasets/country-list) (249 countries, `Name,Code`) with three pasted rows whose header is written `name , CODE`. Japan and France are recognised as duplicates despite `jp` and spaces; Kosovo is new.

### Limits

Up to 20 files, 50 MB each, 1,000,000 output rows.

### Price

One charge per merged file (`file-converted`). If no file can be read, or a key column does not exist, **nothing is charged**.

# Actor input Schema

## `csvUrls` (type: `array`):

Public links to CSV or TSV files. They are merged in this order. Up to 20 files, 50 MB each.

## `csvText` (type: `string`):

Merged after the files above, as one more file. The first line must be the column names.

## `keyColumns` (type: `array`):

Rows with the same values in these columns count as duplicates. Leave empty to compare whole rows.

## `columnMatching` (type: `string`):

Loose treats "Product Name", "product_name" and "PRODUCT-NAME" as the same column. Exact needs the same spelling.

## `columns` (type: `string`):

All columns from every file (missing cells stay empty), or only the columns every file has.

## `trimSpaces` (type: `boolean`):

" Japan " and "Japan" count as the same. The values written to the file are not changed.

## `ignoreCase` (type: `boolean`):

"JP" and "jp" count as the same. The values written to the file are not changed.

## `keep` (type: `string`):

Keep the first row found, or replace it with the last one (useful when later files are newer).

## `addSourceColumn` (type: `boolean`):

Adds a "source" column with the URL each row came from.

## `delimiter` (type: `string`):

Auto detects comma, tab, semicolon or pipe for each file.

## `encoding` (type: `string`):

Auto tries UTF-8, UTF-16, Shift_JIS and Latin-1. The result is always UTF-8.

## Actor input object example

```json
{
  "csvUrls": [
    "https://raw.githubusercontent.com/datasets/country-list/main/data.csv"
  ],
  "csvText": "name , CODE\nJapan, jp \nKosovo,XK\nFrance,FR",
  "keyColumns": [
    "Code"
  ],
  "columnMatching": "loose",
  "columns": "all",
  "trimSpaces": true,
  "ignoreCase": true,
  "keep": "first",
  "addSourceColumn": false,
  "delimiter": "auto",
  "encoding": "auto"
}
```

# Actor output Schema

## `results` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "csvUrls": [
        "https://raw.githubusercontent.com/datasets/country-list/main/data.csv"
    ],
    "csvText": `name , CODE
Japan, jp 
Kosovo,XK
France,FR`,
    "keyColumns": [
        "Code"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("kotaro-project/csv-deduplicate-merge").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "csvUrls": ["https://raw.githubusercontent.com/datasets/country-list/main/data.csv"],
    "csvText": """name , CODE
Japan, jp 
Kosovo,XK
France,FR""",
    "keyColumns": ["Code"],
}

# Run the Actor and wait for it to finish
run = client.actor("kotaro-project/csv-deduplicate-merge").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "csvUrls": [
    "https://raw.githubusercontent.com/datasets/country-list/main/data.csv"
  ],
  "csvText": "name , CODE\\nJapan, jp \\nKosovo,XK\\nFrance,FR",
  "keyColumns": [
    "Code"
  ]
}' |
apify call kotaro-project/csv-deduplicate-merge --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,kotaro-project/csv-deduplicate-merge"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/G13Q3gYO4Smmgf1Yv/builds/Sag09UhlivJTwtrbW/openapi.json
