What does the CSV Row Mover do?
The CSV Row Mover relocates a single selected CSV data row to a new position (such as moving priority rows to the top under headers, moving records to the bottom, or inserting adjacent to another row) while preserving table formatting and RFC 4180 quotation escaping.
Core Concepts
- Data Row Relocation: Moves row $A$ to row index $B$, sliding all intermediate records up or down cleanly.
- Header Isolation: Ensures column headers at line index 0 remain unaffected.
- RFC 4180 Escaping: Preserves all quoted strings, commas, and line breaks without altering cell contents.
How to use the tool?
- Input CSV Data: Paste your CSV spreadsheet data into the input box or click Load Sample.
- Configure Placement:
- Row to Move: Select the data row you wish to move.
- Destination: Choose To the Top (Under Header), To the Bottom, or Immediately Before/After a reference row.
- Move & Export: Click Move Row, then click Copy or Download.
Related Developer Utilities
- CSV Column Mover: Move one selected column to a different position.
- CSV Row Duplicator: Duplicate selected rows a specified number of times.
- CSV Row Filter: Filter CSV rows by comparison conditions.
REST API Integration
blueutils.com provides a free REST API endpoint (POST https://blueutils.com/api/csv/csv-row-mover) for programmatic integration.
API Request Parameters
| Name | Type | Description | Example |
|---|---|---|---|
rawText |
String | Raw CSV text payload. | "id,task\n101,Fix\n102,Test" |
options |
Object | Optional move configurations. | { "sourceIndex": 1, "placement": "top" } |
options.sourceIndex |
Number | Zero-based data row index to move. | 1 |
options.placement |
String | "top", "bottom", "before", "after", "index". |
"top" |
options.referenceRowIndex |
Number | Reference row index if using before/after. | 0 |
options.hasHeader |
Boolean | Whether first row is a header line. | true |
API Request Payload Examples
cURL
curl -X POST https://blueutils.com/api/csv/csv-row-mover \
-H "Content-Type: application/json" \
-d '{
"rawText": "id,task\n101,Fix\n102,Test",
"options": {
"sourceIndex": 1,
"placement": "top",
"hasHeader": true
}
}'Python
import requests
url = "https://blueutils.com/api/csv/csv-row-mover"
payload = {
"rawText": "id,task\n101,Fix\n102,Test",
"options": {
"sourceIndex": 1,
"placement": "top",
"hasHeader": True
}
}
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\": \"id,task\\n101,Fix\\n102,Test\", \"options\": {\"sourceIndex\": 1, \"placement\": \"top\"}}";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://blueutils.com/api/csv/csv-row-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 rows. | "id,task\n102,Test\n101,Fix" |
fromIndex |
Number | Original zero-based data row index. | 1 |
toIndex |
Number | Final zero-based data row index. | 0 |
rowCount |
Number | Total data row count. | 2 |
columnCount |
Number | Total column count. | 2 |
API Response Payload Examples
Success Response (HTTP 200 OK)
{
"isValid": true,
"result": "id,task\n102,Test\n101,Fix",
"headers": ["id", "task"],
"fromIndex": 1,
"toIndex": 0,
"fromDisplayIndex": 2,
"toDisplayIndex": 1,
"placement": "top",
"rowCount": 2,
"columnCount": 2
}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 rows?
Integrating the CSV Row Mover API into CI/CD pipelines, automated ETL pipelines, or autonomous agent workflows provides several practical advantages:
- Rapid Script Validation: Promotes priority records, alert rows, or VIP transactions to top positions before generating executive summary files.
- Optimized Token Efficiency for AI Agents: Reordering rows via an API prevents language models from generating full table tokens in prompt completions.
- Deterministic Accuracy Without Hallucinations: Language models can duplicate or delete adjacent lines when shifting rows in large tables. 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 data row 2 (index 1 in data) to top under header
$lines = Get-Content -Path "input.csv"
$header = $lines[0]
$data = [System.Collections.ArrayList]($lines[1..($lines.Length - 1)])
$item = $data[1]
$data.RemoveAt(1)
$data.Insert(0, $item)
@($header) + $data | Set-Content -Path "output.csv"Linux / Unix (Bash / Shell)
Using standard Linux sed:
# Move line 3 to line 2 (under header)
sed -e '3{h;d}' -e '2{p;g}' 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 data row index 2 (line 3) to data row index 0 (line 2)
if len(rows) > 2:
header = rows[0]
data = rows[1:]
row_to_move = data.pop(2)
data.insert(0, row_to_move)
final_rows = [header] + data
else:
final_rows = rows
with open("output.csv", mode="w", newline="", encoding="utf-8") as outfile:
writer = csv.writer(outfile)
writer.writerows(final_rows)
print("Row moved successfully.")Java
Using standard Java java.nio.file.Files:
import java.nio.file.*;
import java.util.*;
public class MoveCsvRowExample {
public static void main(String[] args) throws Exception {
List<String> lines = new ArrayList<>(Files.readAllLines(Paths.get("input.csv")));
if (lines.size() <= 2) return;
String header = lines.get(0);
List<String> data = new ArrayList<>(lines.subList(1, lines.size()));
String moved = data.remove(2); // remove 3rd data row
data.add(0, moved); // insert at top
List<String> output = new ArrayList<>();
output.add(header);
output.addAll(data);
Files.write(Paths.get("output.csv"), output);
System.out.println("Row moved successfully.");
}
}