What does the CSV Column Merger do?
The CSV Column Merger combines two selected columns into one single column using a customizable separator (such as a space, hyphen, underscore, slash, or custom characters). It allows in-place replacement (combining first_name and last_name into full_name) or appending the merged column as a new field while preserving RFC 4180 quotation formatting and custom delimiters.
Core Concepts
- Concatenation with Separators: Combines values from column $A$ and column $B$ with custom punctuation or delimiters (e.g.
"John" + " " + "Doe" = "John Doe"). - Blank Value Handling: Automatically handles missing or blank fields gracefully without generating dangling or stray separators.
- In-Place or Append Mode: Replaces both original columns in place or preserves them while appending the merged column to the spreadsheet.
How to use the tool?
- Input CSV Data: Paste your CSV spreadsheet data into the input box or click Load Sample.
- Configure Merge:
- First & Second Column: Choose the two distinct columns to combine.
- Separator: Select Space, Hyphen, Underscore, Slash, Comma, or enter a Custom string.
- Merged Header: Enter the column header name (e.g.
full_name). - Keep Original Columns: Check to append rather than replace in place.
- Merge & Export: Click Merge Columns, then click Copy or Download.
Related Developer Utilities
- CSV Column Duplicator: Duplicate an existing column to a new index.
- CSV Column Extractor: Extract specific columns and discard all others.
- CSV Column Mover: Move one selected column to a different position.
REST API Integration
blueutils.com provides a free REST API endpoint (POST https://blueutils.com/api/csv/csv-column-merger) for programmatic integration.
API Request Parameters
| Name | Type | Description | Example |
|---|---|---|---|
rawText |
String | Raw CSV text payload. | "fname,lname\nJohn,Doe" |
options |
Object | Optional merge configurations. | { "firstColIndex": 0, "secondColIndex": 1 } |
options.firstColIndex |
Number | Zero-based index of first column. | 0 |
options.secondColIndex |
Number | Zero-based index of second column. | 1 |
options.separator |
String | Separator string between merged values. | " " |
options.mergedHeaderName |
String | Header name for the combined column. | "full_name" |
options.keepOriginals |
Boolean | If true, appends column rather than replaces. |
false |
options.hasHeader |
Boolean | Whether first line is a header row. | true |
API Request Payload Examples
cURL
curl -X POST https://blueutils.com/api/csv/csv-column-merger \
-H "Content-Type: application/json" \
-d '{
"rawText": "first_name,last_name,department\nAlice,Smith,Engineering\nBob,Jones,Marketing",
"options": {
"firstColIndex": 0,
"secondColIndex": 1,
"separator": " ",
"mergedHeaderName": "full_name",
"keepOriginals": false
}
}'Python
import requests
url = "https://blueutils.com/api/csv/csv-column-merger"
payload = {
"rawText": "first_name,last_name,department\nAlice,Smith,Engineering\nBob,Jones,Marketing",
"options": {
"firstColIndex": 0,
"secondColIndex": 1,
"separator": " ",
"mergedHeaderName": "full_name"
}
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.json())Java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) throws Exception {
String jsonPayload = "{\"rawText\": \"A,B\\n1,2\", \"options\": {\"firstColIndex\": 0, \"secondColIndex\": 1}}";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://blueutils.com/api/csv/csv-column-merger"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(jsonPayload))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}API Response Parameters
| Name | Type | Description | Example |
|---|---|---|---|
isValid |
Boolean | Indicates whether the merge operation succeeded. | true |
result |
String | Resulting CSV spreadsheet text. | "full_name,department\nAlice Smith,..." |
mergedHeaderName |
String | Title assigned to the merged column. | "full_name" |
rowCount |
Number | Total data row count. | 2 |
originalColumnCount |
Number | Column count before merge. | 3 |
finalColumnCount |
Number | Column count after merge. | 2 |
API Response Payload Examples
Success Response (HTTP 200 OK)
{
"isValid": true,
"result": "full_name,department\nAlice Smith,Engineering\nBob Jones,Marketing",
"headers": ["full_name", "department"],
"firstColIndex": 0,
"secondColIndex": 1,
"mergedHeaderName": "full_name",
"separator": " ",
"keepOriginals": false,
"rowCount": 2,
"originalColumnCount": 3,
"finalColumnCount": 2
}Error Response (HTTP 400 Bad Request)
{
"isValid": false,
"error": "Cannot merge a column with itself. Please select two distinct columns."
}Rate Limit Exceeded Response (HTTP 429 Too Many Requests)
{
"error": "API rate limit exceeded. Please wait or contact support@blueutils.com."
}Why use an API to merge CSV columns?
Integrating the CSV Column Merger API into CI/CD pipelines, automated ETL pipelines, or autonomous agent workflows provides several practical advantages:
- Rapid Script Validation: Combine address components (
city,state,zip) or contact attributes (first_name,last_name) into canonical attributes prior to database synchronization. - Optimized Token Efficiency for AI Agents: Executing string concatenations via an API call eliminates token serialization overhead for large tables.
- Deterministic Accuracy Without Hallucinations: Language models can skip missing cells or misalign columns when merging string columns across thousands of records. Delegating processing to a deterministic API guarantees 100% computational accuracy every time without token overhead.
Native Usage
How to achieve the same task locally without external dependencies using native operating system utilities and scripting languages:
Windows (CMD / PowerShell)
Using native PowerShell calculated properties:
# Combine first_name and last_name into full_name
Import-Csv -Path "input.csv" | Select-Object @{Name='full_name';Expression={"$($_.first_name) $($_.last_name)"}}, department | Export-Csv -Path "output.csv" -NoTypeInformationLinux / Unix (Bash / Shell)
Using standard Linux awk:
# Combine columns 1 and 2 with space
awk -F',' 'NR==1 {print "full_name,"$3; next} {print $1" "$2","$3}' input.csv > output.csvPython
Using the Python standard library csv module:
import csv
with open("input.csv", mode="r", encoding="utf-8") as infile:
reader = csv.reader(infile)
header = next(reader)
rows = list(reader)
# Replace col 0 & 1 with merged column
new_header = ["full_name"] + header[2:]
new_rows = [[f"{row[0]} {row[1]}".strip()] + row[2:] for row in rows]
with open("output.csv", mode="w", newline="", encoding="utf-8") as outfile:
writer = csv.writer(outfile)
writer.writerow(new_header)
writer.writerows(new_rows)
print("Columns merged successfully.")Java
Using standard Java java.nio.file.Files:
import java.nio.file.*;
import java.util.*;
public class MergeCsvColumnsExample {
public static void main(String[] args) throws Exception {
List<String> lines = Files.readAllLines(Paths.get("input.csv"));
if (lines.isEmpty()) return;
List<String> output = new ArrayList<>();
output.add("full_name," + lines.get(0).split(",", 3)[2]);
for (int i = 1; i < lines.size(); i++) {
String[] parts = lines.get(i).split(",", 3);
output.add((parts[0] + " " + parts[1]).trim() + (parts.length > 2 ? "," + parts[2] : ""));
}
Files.write(Paths.get("output.csv"), output);
System.out.println("Columns merged successfully.");
}
}