What does the CSV Column Reverser do?
The CSV Column Reverser inverts the horizontal order of columns in a CSV spreadsheet from left-to-right to right-to-left. It rotates headers and data cells simultaneously across every row while preserving RFC 4180 quotation formatting and custom delimiters.
Core Concepts
- Full Horizontal Inversion: Flips column positions across all records such that column $1 \rightarrow N$ becomes column $N \rightarrow 1$.
- Header-Data Synchronization: Ensures each column header remains tightly coupled with its corresponding data cells throughout rotation.
- RFC 4180 Compliance: Retains quoted cells, commas, and line breaks without corruption.
How to use the tool?
- Input CSV Data: Paste your CSV spreadsheet data into the input box or click Load Sample.
- Reverse Columns: Click Reverse Columns to flip the horizontal layout.
- Copy & Export: Inspect the reversed CSV matrix, then click Copy or Download.
Related Developer Utilities
- CSV Column Sorter: Sort CSV rows by any column in ascending or descending order.
- CSV Column Extractor: Extract specific columns and discard others.
- CSV Transposer: Transpose CSV rows into columns and columns into rows.
REST API Integration
blueutils.com provides a free REST API endpoint (POST https://blueutils.com/api/csv/csv-column-reverser) for programmatic integration.
API Request Parameters
| Name | Type | Description | Example |
|---|---|---|---|
payload |
String or Array | Raw CSV text payload OR array-of-arrays to reverse. Aliases: rawText, text, input, csv. |
"id,name,role\n1,Alice,Eng" |
options |
Object | Optional reversal configurations. | { "delimiter": "," } |
options.delimiter |
String | Delimiter character (default is ","). |
"," |
API Request Payload Examples
cURL (String Payload)
curl -X POST https://blueutils.com/api/csv/csv-column-reverser \
-H "Content-Type: application/json" \
-d '{
"payload": "id,first_name,last_name,country\n101,John,Doe,USA\n102,Jane,Smith,UK"
}'Python (Array Payload)
import requests
url = "https://blueutils.com/api/csv/csv-column-reverser"
payload = {
"payload": [
["id", "first_name", "last_name", "country"],
["101", "John", "Doe", "USA"],
["102", "Jane", "Smith", "UK"]
]
}
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 = "{\"payload\": \"A,B,C\\n1,2,3\"}";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://blueutils.com/api/csv/csv-column-reverser"))
.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 reversal succeeded. | true |
result |
String | Resulting CSV text with reversed columns. | "country,last_name,first_name,id\nUSA,..." |
data |
Array | Native array-of-arrays representation of the reversed dataset. | [["country", "last_name", "first_name", "id"], ["USA", "Doe", "John", "101"]] |
originalSize |
Number | Byte size of the original string input. | 73 |
resultSize |
Number | Byte size of the reversed string output. | 73 |
headers |
Array | New reversed header order. | ["country", "last_name", "first_name", "id"] |
originalHeaders |
Array | Original header order. | ["id", "first_name", "last_name", "country"] |
rowCount |
Number | Total row count in resulting data. | 2 |
columnCount |
Number | Total column count per row. | 4 |
API Response Payload Examples
Success Response (HTTP 200 OK)
{
"isValid": true,
"result": "country,last_name,first_name,id\nUSA,Doe,John,101\nUK,Smith,Jane,102",
"data": [
["country", "last_name", "first_name", "id"],
["USA", "Doe", "John", "101"],
["UK", "Smith", "Jane", "102"]
],
"originalSize": 73,
"resultSize": 73,
"headers": ["country", "last_name", "first_name", "id"],
"originalHeaders": ["id", "first_name", "last_name", "country"],
"rowCount": 3,
"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 reverse CSV columns?
Integrating the CSV Column Reverser API into CI/CD pipelines, automated ETL pipelines, or autonomous agent workflows provides several practical advantages:
- Rapid Script Validation: Enables developers to quickly invert matrix ordering for RTL localization or right-aligned spreadsheet reporting schemas.
- Optimized Token Efficiency for AI Agents: Inverting array ordering via API eliminates thousands of token generations for language models.
- Deterministic Accuracy Without Hallucinations: Language models frequently skip columns or jumble indices when reversing multi-column 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 reversal:
# Reverse CSV column order
$lines = Get-Content -Path "input.csv"
$reversed = foreach ($line in $lines) {
$cells = $line.Split(',')
[Array]::Reverse($cells)
$cells -join ','
}
$reversed | Set-Content -Path "output.csv"Linux / Unix (Bash / Shell)
Using standard Linux awk:
# Reverse columns in CSV using awk
awk -F',' '{
for (i=NF; i>1; i--) printf "%s,", $i;
print $1;
}' 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)
reversed_rows = [row[::-1] for row in reader]
with open("output.csv", mode="w", newline="", encoding="utf-8") as outfile:
writer = csv.writer(outfile)
writer.writerows(reversed_rows)
print("Columns reversed successfully.")Java
Using standard Java java.nio.file.Files:
import java.nio.file.*;
import java.util.*;
public class ReverseCsvColumnsExample {
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) {
String[] cells = line.split(",");
List<String> list = Arrays.asList(cells);
Collections.reverse(list);
output.add(String.join(",", list));
}
Files.write(Paths.get("output.csv"), output);
System.out.println("Columns reversed successfully.");
}
}