What does the CSV Column Mover do?
The CSV Column Mover relocates a single selected CSV column to a new target position (such as to the beginning, to the end, or immediately before/after a reference column) across all rows in a spreadsheet while preserving RFC 4180 quotation formatting and custom delimiters.
Core Concepts
- Relational Column Repositioning: Moves a column from index $A$ to index $B$, sliding all intermediate columns left or right accordingly.
- Full Row Synchronization: Rearranges column headers and corresponding cell values simultaneously across every single row.
- RFC 4180 Escaping: Preserves quotes, commas, and line breaks without disturbing cell structure.
How to use the tool?
- Input CSV Data: Paste your CSV spreadsheet data into the input box or click Load Sample.
- Configure Placement:
- Column to Move: Select the source column to reposition.
- Destination: Choose To the Beginning, To the End, or Immediately Before/After a reference column.
- Move & Export: Click Move Column, then click Copy or Download.
Related Developer Utilities
- CSV Column Duplicator: Clone a single column to a new index position.
- CSV Column Extractor: Extract specified columns and discard others.
- CSV Column Reverser: Reverse the horizontal order of columns.
REST API Integration
blueutils.com provides a free REST API endpoint (POST https://blueutils.com/api/csv/csv-column-mover) for programmatic integration.
API Request Parameters
| Name | Type | Description | Example |
|---|---|---|---|
rawText |
String | Raw CSV text payload. | "fname,lname,id\nJohn,Doe,101" |
options |
Object | Optional move configurations. | { "sourceIndex": 2, "placement": "start" } |
options.sourceIndex |
Number | Zero-based index of column to move. | 2 |
options.placement |
String | "start", "end", "before", "after", "index". |
"start" |
options.referenceColumnIndex |
Number | Reference column index if using before/after. | 0 |
options.targetIndex |
Number | Direct target index if placement is "index". |
0 |
API Request Payload Examples
cURL
curl -X POST https://blueutils.com/api/csv/csv-column-mover \
-H "Content-Type: application/json" \
-d '{
"rawText": "first_name,last_name,user_id,email\nAlice,Smith,101,alice@example.com",
"options": {
"sourceIndex": 2,
"placement": "start"
}
}'Python
import requests
url = "https://blueutils.com/api/csv/csv-column-mover"
payload = {
"rawText": "first_name,last_name,user_id,email\nAlice,Smith,101,alice@example.com",
"options": {
"sourceIndex": 2,
"placement": "start"
}
}
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,C\\n1,2,3\", \"options\": {\"sourceIndex\": 2, \"placement\": \"start\"}}";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://blueutils.com/api/csv/csv-column-mover"))
.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 move succeeded. | true |
result |
String | CSV text with reordered columns. | "user_id,first_name,last_name,email\n101,..." |
movedColumnName |
String | Header name of the moved column. | "user_id" |
fromIndex |
Number | Original column index. | 2 |
toIndex |
Number | New column index. | 0 |
rowCount |
Number | Total row count. | 2 |
columnCount |
Number | Total column count. | 4 |
API Response Payload Examples
Success Response (HTTP 200 OK)
{
"isValid": true,
"result": "user_id,first_name,last_name,email\n101,Alice,Smith,alice@example.com",
"headers": ["user_id", "first_name", "last_name", "email"],
"movedColumnName": "user_id",
"fromIndex": 2,
"toIndex": 0,
"placement": "start",
"rowCount": 2,
"columnCount": 4
}Error Response (HTTP 400 Bad Request)
{
"isValid": false,
"error": "CSV input cannot be empty."
}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 move CSV columns?
Integrating the CSV Column Mover API into CI/CD pipelines, automated ETL pipelines, or autonomous agent workflows provides several practical advantages:
- Rapid Script Validation: Enables developers to standardize primary key placement to Column 1 before passing datasets to SQL bulk loaders.
- Optimized Token Efficiency for AI Agents: Reordering columns via an API call prevents language models from generating millions of serialized data tokens.
- Deterministic Accuracy Without Hallucinations: Language models frequently drop columns or misalign cells when shifting fields in large matrices. 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 array manipulation:
# Move column 3 (index 2) to first column
Import-Csv -Path "input.csv" | Select-Object user_id, first_name, last_name, email | Export-Csv -Path "output.csv" -NoTypeInformationLinux / Unix (Bash / Shell)
Using standard Linux awk:
# Move 3rd column to the beginning of CSV
awk -F',' '{print $3","$1","$2","$4}' 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)
rows = list(reader)
# Move index 2 to index 0
for row in rows:
if len(row) > 2:
val = row.pop(2)
row.insert(0, val)
with open("output.csv", mode="w", newline="", encoding="utf-8") as outfile:
writer = csv.writer(outfile)
writer.writerows(rows)
print("Column moved successfully.")Java
Using standard Java java.nio.file.Files:
import java.nio.file.*;
import java.util.*;
public class MoveCsvColumnExample {
public static void main(String[] args) throws Exception {
List<String> lines = Files.readAllLines(Paths.get("input.csv"));
List<String> output = new ArrayList<>();
for (String line : lines) {
List<String> cells = new ArrayList<>(Arrays.asList(line.split(",")));
if (cells.size() > 2) {
String val = cells.remove(2); // remove index 2
cells.add(0, val); // insert at index 0
}
output.add(String.join(",", cells));
}
Files.write(Paths.get("output.csv"), output);
System.out.println("Column moved successfully.");
}
}