Transpose function in Notepad++
Categories:
Transposing Data in Notepad++: Rows to Columns and Vice Versa

Learn how to effectively transpose data in Notepad++ using regular expressions and column mode, converting rows to columns and columns to rows for various data manipulation tasks.
Notepad++ is a powerful text editor widely used by developers and data professionals for its versatility. While it doesn't have a built-in 'transpose' function like spreadsheet software, its robust search and replace capabilities, combined with column mode editing, allow users to achieve complex data transpositions. This article will guide you through various methods to transpose data, converting rows into columns and columns into rows, which is invaluable for reformatting logs, configuration files, or tabular data.
Transposing Rows to Columns (Single Line)
One of the most common transposition needs is to take multiple lines of data and consolidate them into a single line, with each original line becoming a 'column' separated by a delimiter. This is particularly useful for converting lists into comma-separated values (CSV) or other delimited formats.
flowchart TD A["Input: Multi-line data"] B["Find: `\r\n` (Windows) or `\n` (Unix)"] C["Replace: `, ` (or desired delimiter)"] D["Output: Single-line delimited data"] A --> B B --> C C --> D
Process for transposing multiple rows into a single delimited column.
1. Open the 'Replace' Dialog
Press Ctrl+H
to open the 'Replace' dialog box in Notepad++.
2. Configure Search Mode
In the 'Search Mode' section, select 'Regular expression'.
3. Enter Find and Replace Values
In the 'Find what:' field, enter \r\n
for Windows line endings or \n
for Unix/Linux line endings. In the 'Replace with:' field, enter your desired delimiter, such as ,
(comma and space) or \t
(tab character). If you want to remove line breaks without adding a delimiter, simply leave the 'Replace with:' field empty.
4. Execute Replacement
Click 'Replace All' to convert all line breaks into your specified delimiter, effectively transposing the rows into a single column.
Line 1
Line 2
Line 3
Line 4
Original multi-line data
Line 1, Line 2, Line 3, Line 4
Data after replacing \r\n
with ,
\r\n
with \n
, then \n
with your delimiter. Alternatively, a more robust regex like \R
(which matches any Unicode newline sequence) can be used in newer Notepad++ versions.Transposing Columns to Rows (Multi-line Output)
Converting delimited data from a single line (or multiple lines with multiple 'columns') into a multi-line, single-column format requires a slightly different approach using regular expressions to capture and reorder elements. This is useful when you have data like value1, value2, value3
and want to turn it into:
value1 value2 value3
flowchart TD A["Input: Delimited data (e.g., `val1, val2, val3`)"] B["Find: `(.*?),(.*?)` (capturing groups)"] C["Replace: `\1\r\n\2` (reordering with newlines)"] D["Repeat until no more replacements"] E["Output: Multi-line data"] A --> B B --> C C --> D D --> E
Workflow for transposing delimited columns into multiple rows.
1. Open the 'Replace' Dialog
Press Ctrl+H
to open the 'Replace' dialog box.
2. Configure Search Mode
Ensure 'Regular expression' is selected in 'Search Mode'.
3. Define Find and Replace Patterns
For data separated by a comma and space (e.g., val1, val2, val3
):
- 'Find what:':
(.*?),( )?
(This captures the first value, the comma, and an optional space) - 'Replace with:':
\1\r\n
(This replaces the matched pattern with the captured value followed by a new line).
If your delimiter is just a comma, use (.*?),(.*)
for 'Find what:' and \1\r\n\2
for 'Replace with:'. This will convert A,B,C
to A\r\nB,C
. You will need to repeat this process until all commas are replaced.
4. Execute and Repeat
Click 'Replace All'. You will likely need to click 'Replace All' multiple times until the message 'Replace All: 0 occurrences were replaced' appears. This is because the regex processes one delimiter at a time per line.
Apple, Banana, Cherry, Date
Original single-line, comma-separated data
Apple
Banana
Cherry
Date
Data after multiple replacements of (.*?),( )?
with \1\r\n
Advanced Transposition with Column Mode
For more structured data, especially when dealing with fixed-width columns or when you need to manipulate specific parts of multiple lines simultaneously, Notepad++'s column mode (Alt+Shift+Arrow keys or Alt+Mouse Drag) can be incredibly powerful. While not a direct 'transpose' function, it allows for block selections and insertions that can facilitate complex reformatting.

Using column mode to select a vertical block of text in Notepad++.
Column mode is best used for scenarios where you need to extract a specific 'column' of data from multiple lines and then paste it elsewhere, or insert text at a specific column position across many lines. For instance, if you have:
ID: 001 Name: Alice ID: 002 Name: Bob ID: 003 Name: Charlie
And you want to extract just the names, you can use column mode to select 'Alice', 'Bob', 'Charlie' and copy them.